Skip to content

Commit

Permalink
Fixed "Undefined array key -1"
Browse files Browse the repository at this point in the history
  • Loading branch information
kukulich authored and ondrejmirtes committed Mar 19, 2021
1 parent 4136e00 commit cf4fc7d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Parser/TokenIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function tryConsumeTokenType(int $tokenType): bool

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];
}

Expand Down
13 changes: 13 additions & 0 deletions tests/PHPStan/Parser/PhpDocParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3410,6 +3410,19 @@ public function dataParseTagValue(): array
''
),
],
[
'@var',
'$foo string[]',
new InvalidTagValueNode(
'$foo string[]',
new \PHPStan\PhpDocParser\Parser\ParserException(
'$foo',
Lexer::TOKEN_VARIABLE,
0,
Lexer::TOKEN_IDENTIFIER
)
),
],
];
}

Expand Down

0 comments on commit cf4fc7d

Please sign in to comment.