Skip to content

Commit

Permalink
Fix TokensList::getPrevious which was not able to reach very first token
Browse files Browse the repository at this point in the history
  • Loading branch information
Tithugues committed Mar 8, 2023
1 parent 113d4f5 commit aa8a915
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/TokensList.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function getNext()
*/
public function getPrevious(): ?Token
{
for (; $this->idx > 0; --$this->idx) {
for (; $this->idx >= 0; --$this->idx) {
if (
($this->tokens[$this->idx]->type !== Token::TYPE_WHITESPACE)
&& ($this->tokens[$this->idx]->type !== Token::TYPE_COMMENT)
Expand Down
1 change: 1 addition & 0 deletions tests/Lexer/TokensListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public function testGetPrevious(): void
$this->assertEquals($this->tokens[6], $list->getPrevious());
$this->assertEquals($this->tokens[4], $list->getPrevious());
$this->assertEquals($this->tokens[2], $list->getPrevious());
$this->assertEquals($this->tokens[0], $list->getPrevious());
$this->assertNull($list->getPrevious());
}

Expand Down

0 comments on commit aa8a915

Please sign in to comment.