mirror of
https://github.com/danog/phpdoc-parser.git
synced 2024-11-29 20:19:16 +01:00
Fix parsing phpdoc with no trailing whitespace
This commit is contained in:
parent
9d452051cb
commit
7c621a2217
@ -90,7 +90,7 @@ class PhpDocParser
|
||||
$tokens->pushSavePoint();
|
||||
$tokens->next();
|
||||
|
||||
if ($tokens->isCurrentTokenType(Lexer::TOKEN_PHPDOC_TAG) || $tokens->isCurrentTokenType(Lexer::TOKEN_PHPDOC_EOL) || $tokens->isCurrentTokenType(Lexer::TOKEN_CLOSE_PHPDOC) || $tokens->isCurrentTokenType(Lexer::TOKEN_END)) {
|
||||
if ($tokens->isCurrentTokenType(Lexer::TOKEN_PHPDOC_TAG, Lexer::TOKEN_PHPDOC_EOL, Lexer::TOKEN_CLOSE_PHPDOC, Lexer::TOKEN_END)) {
|
||||
$tokens->rollback();
|
||||
break;
|
||||
}
|
||||
@ -491,7 +491,10 @@ class PhpDocParser
|
||||
$tokens->consumeTokenType(Lexer::TOKEN_OTHER); // will throw exception
|
||||
}
|
||||
|
||||
if (!$tokens->isCurrentTokenType(Lexer::TOKEN_PHPDOC_EOL) && !$tokens->isPrecededByHorizontalWhitespace()) {
|
||||
if (
|
||||
!$tokens->isCurrentTokenType(Lexer::TOKEN_PHPDOC_EOL, Lexer::TOKEN_CLOSE_PHPDOC, Lexer::TOKEN_END)
|
||||
&& !$tokens->isPrecededByHorizontalWhitespace()
|
||||
) {
|
||||
$tokens->consumeTokenType(Lexer::TOKEN_HORIZONTAL_WS); // will throw exception
|
||||
}
|
||||
}
|
||||
|
@ -63,9 +63,9 @@ class TokenIterator
|
||||
}
|
||||
|
||||
|
||||
public function isCurrentTokenType(int $tokenType): bool
|
||||
public function isCurrentTokenType(int ...$tokenType): bool
|
||||
{
|
||||
return $this->tokens[$this->index][Lexer::TYPE_OFFSET] === $tokenType;
|
||||
return in_array($this->tokens[$this->index][Lexer::TYPE_OFFSET], $tokenType, true);
|
||||
}
|
||||
|
||||
|
||||
|
@ -692,6 +692,36 @@ class PhpDocParserTest extends TestCase
|
||||
]),
|
||||
];
|
||||
|
||||
yield [
|
||||
'OK with no description and no trailing whitespace',
|
||||
'/** @var Foo $var*/',
|
||||
new PhpDocNode([
|
||||
new PhpDocTagNode(
|
||||
'@var',
|
||||
new VarTagValueNode(
|
||||
new IdentifierTypeNode('Foo'),
|
||||
'$var',
|
||||
''
|
||||
)
|
||||
),
|
||||
]),
|
||||
];
|
||||
|
||||
yield [
|
||||
'OK with no variable name and description and no trailing whitespace',
|
||||
'/** @var Foo*/',
|
||||
new PhpDocNode([
|
||||
new PhpDocTagNode(
|
||||
'@var',
|
||||
new VarTagValueNode(
|
||||
new IdentifierTypeNode('Foo'),
|
||||
'',
|
||||
''
|
||||
)
|
||||
),
|
||||
]),
|
||||
];
|
||||
|
||||
yield [
|
||||
'invalid without type, variable name and description',
|
||||
'/** @var */',
|
||||
|
Loading…
Reference in New Issue
Block a user