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
This commit is contained in:
Jaapio
2024-12-07 10:35:23 +01:00
parent f3558a4c23
commit d46c3297fb
2 changed files with 25 additions and 5 deletions
@@ -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) {
@@ -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());
}
}