diff --git a/src/Parser/PhpDocParser.php b/src/Parser/PhpDocParser.php index c21358cf..15a2aa5c 100644 --- a/src/Parser/PhpDocParser.php +++ b/src/Parser/PhpDocParser.php @@ -1127,15 +1127,13 @@ private function parseAssertParameter(TokenIterator $tokens): array { if ($tokens->isCurrentTokenType(Lexer::TOKEN_THIS_VARIABLE)) { $parameter = '$this'; - $requirePropertyOrMethod = true; $tokens->next(); } else { $parameter = $tokens->currentTokenValue(); - $requirePropertyOrMethod = false; $tokens->consumeTokenType(Lexer::TOKEN_VARIABLE); } - if ($requirePropertyOrMethod || $tokens->isCurrentTokenType(Lexer::TOKEN_ARROW)) { + if ($tokens->isCurrentTokenType(Lexer::TOKEN_ARROW)) { $tokens->consumeTokenType(Lexer::TOKEN_ARROW); $propertyOrMethod = $tokens->currentTokenValue(); diff --git a/tests/PHPStan/Parser/PhpDocParserTest.php b/tests/PHPStan/Parser/PhpDocParserTest.php index b448dc24..97d6cbfe 100644 --- a/tests/PHPStan/Parser/PhpDocParserTest.php +++ b/tests/PHPStan/Parser/PhpDocParserTest.php @@ -4563,21 +4563,56 @@ public function provideAssertTagsData(): Iterator ]; yield [ - 'invalid $this', + 'OK $this', '/** @phpstan-assert Type $this */', new PhpDocNode([ new PhpDocTagNode( '@phpstan-assert', - new InvalidTagValueNode( - 'Type $this', - new ParserException( - '*/', - Lexer::TOKEN_CLOSE_PHPDOC, - 31, - Lexer::TOKEN_ARROW, - null, - 1 - ) + new AssertTagValueNode( + new IdentifierTypeNode('Type'), + '$this', + false, + '' + ) + ), + ]), + ]; + + yield [ + 'OK $this with description', + '/** @phpstan-assert Type $this assert Type to $this */', + new PhpDocNode([ + new PhpDocTagNode( + '@phpstan-assert', + new AssertTagValueNode( + new IdentifierTypeNode('Type'), + '$this', + false, + 'assert Type to $this' + ) + ), + ]), + ]; + + yield [ + 'OK $this with generic type', + '/** @phpstan-assert GenericType $this */', + new PhpDocNode([ + new PhpDocTagNode( + '@phpstan-assert', + new AssertTagValueNode( + new GenericTypeNode( + new IdentifierTypeNode('GenericType'), + [ + new IdentifierTypeNode('T'), + ], + [ + GenericTypeNode::VARIANCE_INVARIANT, + ] + ), + '$this', + false, + '' ) ), ]),