Skip to content

Commit d46c329

Browse files
committed
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
1 parent f3558a4 commit d46c329

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)