diff --git a/src/Parser/TokenIterator.php b/src/Parser/TokenIterator.php index 05fe5d7..d2eebd5 100644 --- a/src/Parser/TokenIterator.php +++ b/src/Parser/TokenIterator.php @@ -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]; } diff --git a/tests/PHPStan/Parser/PhpDocParserTest.php b/tests/PHPStan/Parser/PhpDocParserTest.php index 85d78e4..1e06925 100644 --- a/tests/PHPStan/Parser/PhpDocParserTest.php +++ b/tests/PHPStan/Parser/PhpDocParserTest.php @@ -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 + ) + ), + ], ]; }