Skip to content

Commit 83695f4

Browse files
committed
Invalid Doctrine tag with backslash: return InvalidTagValueNode
parse() threw ParserException for an invalid @\Foo(...) tag. Other tags already get InvalidTagValueNode in parseTagValue(). Amp-Thread-ID: https://ampcode.com/threads/T-01a17930-0285-73c5-a957-4325c77aa1b2
1 parent d10f40e commit 83695f4

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

‎src/Parser/PhpDocParser.php‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,21 @@ private function parseChild(TokenIterator $tokens): Ast\PhpDoc\PhpDocChildNode
149149
$tagStartLine = $tokens->currentTokenLine();
150150
$tagStartIndex = $tokens->currentTokenIndex();
151151

152+
try {
153+
$tokens->pushSavePoint();
154+
$tagValue = $this->parseDoctrineTagValue($tokens, $tag);
155+
$tokens->dropSavePoint();
156+
157+
} catch (ParserException $e) {
158+
$tokens->rollback();
159+
$tagValue = new Ast\PhpDoc\InvalidTagValueNode($this->parseOptionalDescription($tokens, false), $e);
160+
}
161+
152162
return $this->enrichWithAttributes($tokens, new Ast\PhpDoc\PhpDocTagNode(
153163
$tag,
154164
$this->enrichWithAttributes(
155165
$tokens,
156-
$this->parseDoctrineTagValue($tokens, $tag),
166+
$tagValue,
157167
$tagStartLine,
158168
$tagStartIndex,
159169
),

‎tests/PHPStan/Parser/PhpDocParserTest.php‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6386,6 +6386,40 @@ public function provideTagsWithBackslash(): Iterator
63866386
),
63876387
]),
63886388
];
6389+
6390+
yield [
6391+
'Invalid Doctrine tag with backslash keeps the next tags',
6392+
'/**' . PHP_EOL .
6393+
' * @\\ORM\\Table(\'user\')' . PHP_EOL .
6394+
' * @param int $a' . PHP_EOL .
6395+
' */',
6396+
new PhpDocNode([
6397+
new PhpDocTagNode(
6398+
'@\\ORM\\Table',
6399+
new InvalidTagValueNode(
6400+
"('user')",
6401+
new ParserException(
6402+
"'user'",
6403+
Lexer::TOKEN_SINGLE_QUOTED_STRING,
6404+
19,
6405+
Lexer::TOKEN_DOUBLE_QUOTED_STRING,
6406+
null,
6407+
2,
6408+
),
6409+
),
6410+
),
6411+
new PhpDocTagNode(
6412+
'@param',
6413+
new ParamTagValueNode(
6414+
new IdentifierTypeNode('int'),
6415+
false,
6416+
'$a',
6417+
'',
6418+
false,
6419+
),
6420+
),
6421+
]),
6422+
];
63896423
}
63906424

63916425
public function provideSelfOutTagsData(): Iterator

0 commit comments

Comments
 (0)