Skip to content

Commit

Permalink
Do not require description
Browse files Browse the repository at this point in the history
  • Loading branch information
rvanvelzen committed Jun 8, 2022
1 parent 184e730 commit d9b660c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/Ast/PhpDoc/TypelessParamTagValueNode.php
Expand Up @@ -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)
Expand Down
20 changes: 1 addition & 19 deletions src/Parser/PhpDocParser.php
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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) {
Expand Down
13 changes: 5 additions & 8 deletions tests/PHPStan/Parser/PhpDocParserTest.php
Expand Up @@ -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
)
),
]),
Expand Down

0 comments on commit d9b660c

Please sign in to comment.