Skip to content

Commit

Permalink
@template T as bound
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Nov 18, 2019
1 parent 3edb515 commit 62c6de6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Parser/PhpDocParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ private function parseTemplateTagValue(TokenIterator $tokens): Ast\PhpDoc\Templa
$name = $tokens->currentTokenValue();
$tokens->consumeTokenType(Lexer::TOKEN_IDENTIFIER);

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

} else {
Expand Down
30 changes: 30 additions & 0 deletions tests/PHPStan/Parser/PhpDocParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2319,6 +2319,21 @@ public function provideTemplateTagsData(): \Iterator
]),
];

yield [
'OK without description',
'/** @template T as DateTime */',
new PhpDocNode([
new PhpDocTagNode(
'@template',
new TemplateTagValueNode(
'T',
new IdentifierTypeNode('DateTime'),
''
)
),
]),
];

yield [
'OK with bound and description',
'/** @template T of DateTime the value type */',
Expand All @@ -2334,6 +2349,21 @@ public function provideTemplateTagsData(): \Iterator
]),
];

yield [
'OK with bound and description',
'/** @template T as DateTime the value type */',
new PhpDocNode([
new PhpDocTagNode(
'@template',
new TemplateTagValueNode(
'T',
new IdentifierTypeNode('DateTime'),
'the value type'
)
),
]),
];

yield [
'invalid without bound and description',
'/** @template */',
Expand Down

0 comments on commit 62c6de6

Please sign in to comment.