Skip to content

Commit

Permalink
Merge pull request #394 from phpDocumentor/bugfix/phpstan-parser-2.0
Browse files Browse the repository at this point in the history
Fix compatibility issue with phpstan 2.0 parser
  • Loading branch information
jaapio authored Dec 7, 2024
2 parents f3558a4 + d46c329 commit e5e7841
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 e5e7841

Please sign in to comment.