Skip to content

Commit cf4fc7d

Browse files
kukulichondrejmirtes
authored andcommitted
Fixed "Undefined array key -1"
1 parent 4136e00 commit cf4fc7d

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Diff for: src/Parser/TokenIterator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function tryConsumeTokenType(int $tokenType): bool
124124

125125
public function getSkippedHorizontalWhiteSpaceIfAny(): string
126126
{
127-
if ($this->tokens[$this->index - 1][Lexer::TYPE_OFFSET] === Lexer::TOKEN_HORIZONTAL_WS) {
127+
if ($this->index > 0 && $this->tokens[$this->index - 1][Lexer::TYPE_OFFSET] === Lexer::TOKEN_HORIZONTAL_WS) {
128128
return $this->tokens[$this->index - 1][Lexer::VALUE_OFFSET];
129129
}
130130

Diff for: tests/PHPStan/Parser/PhpDocParserTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -3410,6 +3410,19 @@ public function dataParseTagValue(): array
34103410
''
34113411
),
34123412
],
3413+
[
3414+
'@var',
3415+
'$foo string[]',
3416+
new InvalidTagValueNode(
3417+
'$foo string[]',
3418+
new \PHPStan\PhpDocParser\Parser\ParserException(
3419+
'$foo',
3420+
Lexer::TOKEN_VARIABLE,
3421+
0,
3422+
Lexer::TOKEN_IDENTIFIER
3423+
)
3424+
),
3425+
],
34133426
];
34143427
}
34153428

0 commit comments

Comments
 (0)