Skip to content

Commit

Permalink
Fix compatibility issue with phpstan 2.0 parser
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jaapio committed Dec 7, 2024
1 parent f3558a4 commit d46c329
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ public function create(string $tagLine, ?TypeContext $context = null): Tag
{
$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) {
Expand Down
18 changes: 18 additions & 0 deletions tests/integration/InterpretingDocBlocksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,4 +463,22 @@ public function testProcessTemplateTag(): void
$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());
}
}

0 comments on commit d46c329

Please sign in to comment.