Skip to content

Commit a6d1352

Browse files
committed
Fix @var tag with $this
1 parent 0331e88 commit a6d1352

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

Diff for: src/Parser/PhpDocParser.php

+3
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,9 @@ private function parseOptionalVariableName(TokenIterator $tokens): string
358358
if ($tokens->isCurrentTokenType(Lexer::TOKEN_VARIABLE)) {
359359
$parameterName = $tokens->currentTokenValue();
360360
$tokens->next();
361+
} elseif ($tokens->isCurrentTokenType(Lexer::TOKEN_THIS_VARIABLE)) {
362+
$parameterName = '$this';
363+
$tokens->next();
361364

362365
} else {
363366
$parameterName = '';

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

+60
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,66 @@ public function provideVarTagsData(): \Iterator
417417
]),
418418
];
419419

420+
yield [
421+
'OK without description with variable $this',
422+
'/** @var Foo $this */',
423+
new PhpDocNode([
424+
new PhpDocTagNode(
425+
'@var',
426+
new VarTagValueNode(
427+
new IdentifierTypeNode('Foo'),
428+
'$this',
429+
''
430+
)
431+
),
432+
]),
433+
];
434+
435+
yield [
436+
'OK without description and with no space between type and variable name with variable $this',
437+
'/** @var Foo$this */',
438+
new PhpDocNode([
439+
new PhpDocTagNode(
440+
'@var',
441+
new VarTagValueNode(
442+
new IdentifierTypeNode('Foo'),
443+
'$this',
444+
''
445+
)
446+
),
447+
]),
448+
];
449+
450+
yield [
451+
'OK with description with variable $this',
452+
'/** @var Foo $this Testing */',
453+
new PhpDocNode([
454+
new PhpDocTagNode(
455+
'@var',
456+
new VarTagValueNode(
457+
new IdentifierTypeNode('Foo'),
458+
'$this',
459+
'Testing'
460+
)
461+
),
462+
]),
463+
];
464+
465+
yield [
466+
'OK with description and with no space between type and variable name with variable $this',
467+
'/** @var Foo$this Testing */',
468+
new PhpDocNode([
469+
new PhpDocTagNode(
470+
'@var',
471+
new VarTagValueNode(
472+
new IdentifierTypeNode('Foo'),
473+
'$this',
474+
'Testing'
475+
)
476+
),
477+
]),
478+
];
479+
420480
yield [
421481
'OK with variable name and description and without all optional spaces',
422482
'/** @var(Foo)$foo#desc*/',

0 commit comments

Comments
 (0)