Skip to content

Commit 62c6de6

Browse files
committed
@template T as bound
1 parent 3edb515 commit 62c6de6

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

Diff for: src/Parser/PhpDocParser.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ private function parseTemplateTagValue(TokenIterator $tokens): Ast\PhpDoc\Templa
320320
$name = $tokens->currentTokenValue();
321321
$tokens->consumeTokenType(Lexer::TOKEN_IDENTIFIER);
322322

323-
if ($tokens->tryConsumeTokenValue('of')) {
323+
if ($tokens->tryConsumeTokenValue('of') || $tokens->tryConsumeTokenValue('as')) {
324324
$bound = $this->typeParser->parse($tokens);
325325

326326
} else {

Diff for: tests/PHPStan/Parser/PhpDocParserTest.php

+30
Original file line numberDiff line numberDiff line change
@@ -2319,6 +2319,21 @@ public function provideTemplateTagsData(): \Iterator
23192319
]),
23202320
];
23212321

2322+
yield [
2323+
'OK without description',
2324+
'/** @template T as DateTime */',
2325+
new PhpDocNode([
2326+
new PhpDocTagNode(
2327+
'@template',
2328+
new TemplateTagValueNode(
2329+
'T',
2330+
new IdentifierTypeNode('DateTime'),
2331+
''
2332+
)
2333+
),
2334+
]),
2335+
];
2336+
23222337
yield [
23232338
'OK with bound and description',
23242339
'/** @template T of DateTime the value type */',
@@ -2334,6 +2349,21 @@ public function provideTemplateTagsData(): \Iterator
23342349
]),
23352350
];
23362351

2352+
yield [
2353+
'OK with bound and description',
2354+
'/** @template T as DateTime the value type */',
2355+
new PhpDocNode([
2356+
new PhpDocTagNode(
2357+
'@template',
2358+
new TemplateTagValueNode(
2359+
'T',
2360+
new IdentifierTypeNode('DateTime'),
2361+
'the value type'
2362+
)
2363+
),
2364+
]),
2365+
];
2366+
23372367
yield [
23382368
'invalid without bound and description',
23392369
'/** @template */',

0 commit comments

Comments
 (0)