Skip to content

Commit e5e7841

Browse files
authored
Merge pull request #394 from phpDocumentor/bugfix/phpstan-parser-2.0
Fix compatibility issue with phpstan 2.0 parser
2 parents f3558a4 + d46c329 commit e5e7841

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,13 @@ public function create(string $tagLine, ?TypeContext $context = null): Tag
7575
{
7676
$tokens = $this->tokenizeLine($tagLine);
7777
$ast = $this->parser->parseTag($tokens);
78-
if (property_exists($ast->value, 'description') === true) {
79-
$ast->value->setAttribute(
80-
'description',
81-
$ast->value->description . $tokens->joinUntil(Lexer::TOKEN_END)
82-
);
78+
if (class_exists(ParserConfig::class) === false) {
79+
if (property_exists($ast->value, 'description') === true) {
80+
$ast->value->setAttribute(
81+
'description',
82+
$ast->value->description . $tokens->joinUntil(Lexer::TOKEN_END)
83+
);
84+
}
8385
}
8486

8587
if ($context === null) {

tests/integration/InterpretingDocBlocksTest.php

+18
Original file line numberDiff line numberDiff line change
@@ -463,4 +463,22 @@ public function testProcessTemplateTag(): void
463463
$docblock->getTags()
464464
);
465465
}
466+
467+
public function testParamTagDescriptionIsCorrectly(): void
468+
{
469+
$docComment = '
470+
/**
471+
* @param int $baz Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas varius, tellus in cursus
472+
* dictum, justo odio sagittis velit, id iaculis mi dui id nisi.
473+
*/
474+
';
475+
476+
$factory = DocBlockFactory::createInstance();
477+
$docblock = $factory->create($docComment);
478+
479+
$paramTags = $docblock->getTagsWithTypeByName('param')[0];
480+
481+
self::assertSame('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas varius, tellus in cursus
482+
dictum, justo odio sagittis velit, id iaculis mi dui id nisi.', (string) $paramTags->getDescription());
483+
}
466484
}

0 commit comments

Comments
 (0)