Skip to content

Commit

Permalink
Fix @var tag with $this
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Dec 13, 2019
1 parent 0331e88 commit a6d1352
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Parser/PhpDocParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ private function parseOptionalVariableName(TokenIterator $tokens): string
if ($tokens->isCurrentTokenType(Lexer::TOKEN_VARIABLE)) {
$parameterName = $tokens->currentTokenValue();
$tokens->next();
} elseif ($tokens->isCurrentTokenType(Lexer::TOKEN_THIS_VARIABLE)) {
$parameterName = '$this';
$tokens->next();

} else {
$parameterName = '';
Expand Down
60 changes: 60 additions & 0 deletions tests/PHPStan/Parser/PhpDocParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,66 @@ public function provideVarTagsData(): \Iterator
]),
];

yield [
'OK without description with variable $this',
'/** @var Foo $this */',
new PhpDocNode([
new PhpDocTagNode(
'@var',
new VarTagValueNode(
new IdentifierTypeNode('Foo'),
'$this',
''
)
),
]),
];

yield [
'OK without description and with no space between type and variable name with variable $this',
'/** @var Foo$this */',
new PhpDocNode([
new PhpDocTagNode(
'@var',
new VarTagValueNode(
new IdentifierTypeNode('Foo'),
'$this',
''
)
),
]),
];

yield [
'OK with description with variable $this',
'/** @var Foo $this Testing */',
new PhpDocNode([
new PhpDocTagNode(
'@var',
new VarTagValueNode(
new IdentifierTypeNode('Foo'),
'$this',
'Testing'
)
),
]),
];

yield [
'OK with description and with no space between type and variable name with variable $this',
'/** @var Foo$this Testing */',
new PhpDocNode([
new PhpDocTagNode(
'@var',
new VarTagValueNode(
new IdentifierTypeNode('Foo'),
'$this',
'Testing'
)
),
]),
];

yield [
'OK with variable name and description and without all optional spaces',
'/** @var(Foo)$foo#desc*/',
Expand Down

0 comments on commit a6d1352

Please sign in to comment.