Require whitespace before description with limited start tokens

This commit is contained in:
Richard van Velzen 2022-06-08 14:22:21 +02:00 committed by Ondřej Mirtes
parent b75949e747
commit d579798d2f
2 changed files with 72 additions and 12 deletions

View File

@ -474,6 +474,10 @@ class PhpDocParser
$tokens->consumeTokenType(Lexer::TOKEN_OTHER); // will throw exception $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; return $this->parseText($tokens)->text;

View File

@ -1310,6 +1310,58 @@ class PhpDocParserTest extends TestCase
), ),
]), ]),
]; ];
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
)
)
),
]),
];
} }
@ -2104,10 +2156,14 @@ class PhpDocParserTest extends TestCase
new PhpDocNode([ new PhpDocNode([
new PhpDocTagNode( new PhpDocTagNode(
'@var', '@var',
new VarTagValueNode( new InvalidTagValueNode(
new IdentifierTypeNode('callable'), 'callable(int)',
'', new ParserException(
'(int)' '(',
Lexer::TOKEN_OPEN_PARENTHESES,
17,
Lexer::TOKEN_HORIZONTAL_WS
)
) )
), ),
]), ]),
@ -4076,14 +4132,14 @@ Finder::findFiles('*.php')
new PhpDocNode([ new PhpDocNode([
new PhpDocTagNode( new PhpDocTagNode(
'@return', '@return',
new ReturnTagValueNode( new InvalidTagValueNode(
new GenericTypeNode( 'Foo <strong>Important description',
new IdentifierTypeNode('Foo'), new ParserException(
[ 'Important',
new IdentifierTypeNode('strong'), Lexer::TOKEN_IDENTIFIER,
] 27,
), Lexer::TOKEN_HORIZONTAL_WS
'Important description' )
) )
), ),
]), ]),