Skip to content

Commit a53805e

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 a53805e

2 files changed

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

63916422
public function provideSelfOutTagsData(): Iterator

0 commit comments

Comments
 (0)