Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/Parser/PhpDocParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,21 @@ private function parseChild(TokenIterator $tokens): Ast\PhpDoc\PhpDocChildNode
$tagStartLine = $tokens->currentTokenLine();
$tagStartIndex = $tokens->currentTokenIndex();

try {
$tokens->pushSavePoint();
$tagValue = $this->parseDoctrineTagValue($tokens, $tag);
$tokens->dropSavePoint();

} catch (ParserException $e) {
$tokens->rollback();
$tagValue = new Ast\PhpDoc\InvalidTagValueNode($this->parseOptionalDescription($tokens, false), $e);
}

return $this->enrichWithAttributes($tokens, new Ast\PhpDoc\PhpDocTagNode(
$tag,
$this->enrichWithAttributes(
$tokens,
$this->parseDoctrineTagValue($tokens, $tag),
$tagValue,
$tagStartLine,
$tagStartIndex,
),
Expand Down
31 changes: 31 additions & 0 deletions tests/PHPStan/Parser/PhpDocParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6386,6 +6386,37 @@ public function provideTagsWithBackslash(): Iterator
),
]),
];

yield [
'Invalid Doctrine tag with backslash keeps the next tags',
"/**\n * @\\ORM\\Table('user')\n * @param int \$a\n */",
new PhpDocNode([
new PhpDocTagNode(
'@\\ORM\\Table',
new InvalidTagValueNode(
"('user')",
new ParserException(
"'user'",
Lexer::TOKEN_SINGLE_QUOTED_STRING,
19,
Lexer::TOKEN_DOUBLE_QUOTED_STRING,
null,
2,
),
),
),
new PhpDocTagNode(
'@param',
new ParamTagValueNode(
new IdentifierTypeNode('int'),
false,
'$a',
'',
false,
),
),
]),
];
}

public function provideSelfOutTagsData(): Iterator
Expand Down
Loading