Fixed "Undefined array key -1"

This commit is contained in:
Jaroslav Hanslík 2021-03-19 10:32:01 +01:00 committed by Ondrej Mirtes
parent 4136e0056a
commit cf4fc7d2ae
No known key found for this signature in database
GPG Key ID: 8E730BA25823D8B5
2 changed files with 14 additions and 1 deletions

View File

@ -124,7 +124,7 @@ class TokenIterator
public function getSkippedHorizontalWhiteSpaceIfAny(): string
{
if ($this->tokens[$this->index - 1][Lexer::TYPE_OFFSET] === Lexer::TOKEN_HORIZONTAL_WS) {
if ($this->index > 0 && $this->tokens[$this->index - 1][Lexer::TYPE_OFFSET] === Lexer::TOKEN_HORIZONTAL_WS) {
return $this->tokens[$this->index - 1][Lexer::VALUE_OFFSET];
}

View File

@ -3410,6 +3410,19 @@ Finder::findFiles('*.php')
''
),
],
[
'@var',
'$foo string[]',
new InvalidTagValueNode(
'$foo string[]',
new \PHPStan\PhpDocParser\Parser\ParserException(
'$foo',
Lexer::TOKEN_VARIABLE,
0,
Lexer::TOKEN_IDENTIFIER
)
),
],
];
}