From d46c3297fbcb1c83f52cf273937bb85826ffd3f0 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Sat, 7 Dec 2024 10:35:23 +0100 Subject: [PATCH] Fix compatibility issue with phpstan 2.0 parser The phpstan 2.0 release contains a fix which resolves the existing bug in the old parser that didn't take the whole description when it was multiline. Now the workaround is disabled when using phpstan parser v2 Fixes #393 --- .../Tags/Factory/AbstractPHPStanFactory.php | 12 +++++++----- .../integration/InterpretingDocBlocksTest.php | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php b/src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php index 872a266..e5b4e41 100644 --- a/src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php +++ b/src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php @@ -75,11 +75,13 @@ class AbstractPHPStanFactory implements Factory { $tokens = $this->tokenizeLine($tagLine); $ast = $this->parser->parseTag($tokens); - if (property_exists($ast->value, 'description') === true) { - $ast->value->setAttribute( - 'description', - $ast->value->description . $tokens->joinUntil(Lexer::TOKEN_END) - ); + if (class_exists(ParserConfig::class) === false) { + if (property_exists($ast->value, 'description') === true) { + $ast->value->setAttribute( + 'description', + $ast->value->description . $tokens->joinUntil(Lexer::TOKEN_END) + ); + } } if ($context === null) { diff --git a/tests/integration/InterpretingDocBlocksTest.php b/tests/integration/InterpretingDocBlocksTest.php index 5c24076..95c44c9 100644 --- a/tests/integration/InterpretingDocBlocksTest.php +++ b/tests/integration/InterpretingDocBlocksTest.php @@ -463,4 +463,22 @@ DOCBLOCK; $docblock->getTags() ); } + + public function testParamTagDescriptionIsCorrectly(): void + { + $docComment = ' + /** + * @param int $baz Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas varius, tellus in cursus + * dictum, justo odio sagittis velit, id iaculis mi dui id nisi. + */ +'; + + $factory = DocBlockFactory::createInstance(); + $docblock = $factory->create($docComment); + + $paramTags = $docblock->getTagsWithTypeByName('param')[0]; + + self::assertSame('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas varius, tellus in cursus +dictum, justo odio sagittis velit, id iaculis mi dui id nisi.', (string) $paramTags->getDescription()); + } }