Skip to content

Commit

Permalink
Require whitespace before description with limited start tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
rvanvelzen authored and ondrejmirtes committed Jun 8, 2022
1 parent b75949e commit d579798
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 12 deletions.
4 changes: 4 additions & 0 deletions src/Parser/PhpDocParser.php
Expand Up @@ -474,6 +474,10 @@ private function parseOptionalDescription(TokenIterator $tokens, bool $limitStar

$tokens->consumeTokenType(Lexer::TOKEN_OTHER); // will throw exception
}

if (!$tokens->isCurrentTokenType(Lexer::TOKEN_PHPDOC_EOL) && !$tokens->isPrecededByHorizontalWhitespace()) {
$tokens->consumeTokenType(Lexer::TOKEN_HORIZONTAL_WS); // will throw exception
}
}

return $this->parseText($tokens)->text;
Expand Down
80 changes: 68 additions & 12 deletions tests/PHPStan/Parser/PhpDocParserTest.php
Expand Up @@ -1310,6 +1310,58 @@ public function provideReturnTagsData(): Iterator
),
]),
];

yield [
'OK variadic callable',
'/** @return \Closure(int ...$u, string): string */',
new PhpDocNode([
new PhpDocTagNode(
'@return',
new ReturnTagValueNode(
new CallableTypeNode(
new IdentifierTypeNode('\Closure'),
[
new CallableTypeParameterNode(
new IdentifierTypeNode('int'),
false,
true,
'$u',
false
),
new CallableTypeParameterNode(
new IdentifierTypeNode('string'),
false,
false,
'',
false
),
],
new IdentifierTypeNode('string')
),
''
)
),
]),
];

yield [
'invalid variadic callable',
'/** @return \Closure(...int, string): string */',
new PhpDocNode([
new PhpDocTagNode(
'@return',
new InvalidTagValueNode(
'\Closure(...int, string): string',
new ParserException(
'(',
Lexer::TOKEN_OPEN_PARENTHESES,
20,
Lexer::TOKEN_HORIZONTAL_WS
)
)
),
]),
];
}


Expand Down Expand Up @@ -2104,10 +2156,14 @@ public function provideSingleLinePhpDocData(): Iterator
new PhpDocNode([
new PhpDocTagNode(
'@var',
new VarTagValueNode(
new IdentifierTypeNode('callable'),
'',
'(int)'
new InvalidTagValueNode(
'callable(int)',
new ParserException(
'(',
Lexer::TOKEN_OPEN_PARENTHESES,
17,
Lexer::TOKEN_HORIZONTAL_WS
)
)
),
]),
Expand Down Expand Up @@ -4076,14 +4132,14 @@ public function provideDescriptionWithOrWithoutHtml(): Iterator
new PhpDocNode([
new PhpDocTagNode(
'@return',
new ReturnTagValueNode(
new GenericTypeNode(
new IdentifierTypeNode('Foo'),
[
new IdentifierTypeNode('strong'),
]
),
'Important description'
new InvalidTagValueNode(
'Foo <strong>Important description',
new ParserException(
'Important',
Lexer::TOKEN_IDENTIFIER,
27,
Lexer::TOKEN_HORIZONTAL_WS
)
)
),
]),
Expand Down

0 comments on commit d579798

Please sign in to comment.