Skip to content

Commit aa8a915

Browse files
committed
Fix TokensList::getPrevious which was not able to reach very first token
1 parent 113d4f5 commit aa8a915

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/TokensList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function getNext()
119119
*/
120120
public function getPrevious(): ?Token
121121
{
122-
for (; $this->idx > 0; --$this->idx) {
122+
for (; $this->idx >= 0; --$this->idx) {
123123
if (
124124
($this->tokens[$this->idx]->type !== Token::TYPE_WHITESPACE)
125125
&& ($this->tokens[$this->idx]->type !== Token::TYPE_COMMENT)

tests/Lexer/TokensListTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public function testGetPrevious(): void
7979
$this->assertEquals($this->tokens[6], $list->getPrevious());
8080
$this->assertEquals($this->tokens[4], $list->getPrevious());
8181
$this->assertEquals($this->tokens[2], $list->getPrevious());
82+
$this->assertEquals($this->tokens[0], $list->getPrevious());
8283
$this->assertNull($list->getPrevious());
8384
}
8485

0 commit comments

Comments
 (0)