diff --git a/src/Ast/PhpDoc/TypelessParamTagValueNode.php b/src/Ast/PhpDoc/TypelessParamTagValueNode.php index fc460a5b..8b982954 100644 --- a/src/Ast/PhpDoc/TypelessParamTagValueNode.php +++ b/src/Ast/PhpDoc/TypelessParamTagValueNode.php @@ -19,7 +19,7 @@ class TypelessParamTagValueNode implements PhpDocTagValueNode /** @var string */ public $parameterName; - /** @var string */ + /** @var string (may be empty) */ public $description; public function __construct(bool $isVariadic, string $parameterName, string $description, bool $isReference = false) diff --git a/src/Parser/PhpDocParser.php b/src/Parser/PhpDocParser.php index d33f5879..0679ff5c 100644 --- a/src/Parser/PhpDocParser.php +++ b/src/Parser/PhpDocParser.php @@ -249,13 +249,12 @@ private function parseParamTagValue(TokenIterator $tokens): Ast\PhpDoc\PhpDocTag $isReference = $tokens->tryConsumeTokenType(Lexer::TOKEN_REFERENCE); $isVariadic = $tokens->tryConsumeTokenType(Lexer::TOKEN_VARIADIC); $parameterName = $this->parseRequiredVariableName($tokens); + $description = $this->parseOptionalDescription($tokens); if ($type !== null) { - $description = $this->parseOptionalDescription($tokens); return new Ast\PhpDoc\ParamTagValueNode($type, $isVariadic, $parameterName, $description, $isReference); } - $description = $this->parseRequiredDescription($tokens); return new Ast\PhpDoc\TypelessParamTagValueNode($isVariadic, $parameterName, $description, $isReference); } @@ -482,23 +481,6 @@ private function parseRequiredVariableName(TokenIterator $tokens): string return $parameterName; } - private function parseRequiredDescription(TokenIterator $tokens): string - { - $tokens->pushSavePoint(); - - $description = $this->parseOptionalDescription($tokens); - - if (strlen($description) === 0) { - $tokens->rollback(); - - $tokens->consumeTokenType(Lexer::TOKEN_OTHER); - } - - $tokens->dropSavePoint(); - - return $description; - } - private function parseOptionalDescription(TokenIterator $tokens, bool $limitStartToken = false): string { if ($limitStartToken) { diff --git a/tests/PHPStan/Parser/PhpDocParserTest.php b/tests/PHPStan/Parser/PhpDocParserTest.php index d9646c86..e91a4042 100644 --- a/tests/PHPStan/Parser/PhpDocParserTest.php +++ b/tests/PHPStan/Parser/PhpDocParserTest.php @@ -462,19 +462,16 @@ public function provideTypelessParamTagsData(): Iterator ]; yield [ - 'invalid without type and description', + 'OK without type and description', '/** @param $foo */', new PhpDocNode([ new PhpDocTagNode( '@param', - new InvalidTagValueNode( + new TypelessParamTagValueNode( + false, '$foo', - new ParserException( - '*/', - Lexer::TOKEN_CLOSE_PHPDOC, - 16, - Lexer::TOKEN_OTHER - ) + '', + false ) ), ]),