Skip to content

Commit

Permalink
Merge pull request #463 from greg0ire/dont-cast-null
Browse files Browse the repository at this point in the history
Do not cast null to array
  • Loading branch information
greg0ire committed Dec 12, 2022
2 parents 3587ab5 + fd04499 commit 9e034d7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/Doctrine/Common/Annotations/DocLexer.php
Expand Up @@ -130,10 +130,14 @@ protected function getType(&$value)
}

/** @return array{value: int|string, type:self::T_*|null, position:int} */
public function peek(): array
public function peek(): ?array
{
$token = parent::peek();

if ($token === null) {
return null;
}

return (array) $token;
}
}
2 changes: 0 additions & 2 deletions phpstan.neon
Expand Up @@ -22,5 +22,3 @@ parameters:

# That tag is empty on purpose
- '#PHPDoc tag @var has invalid value \(\)\: Unexpected token "\*/", expected type at offset 9#'
# Backwards-compatibility
- '#^Return type.*of method.*DocLexer::peek.*should be compatible.*$#'
5 changes: 5 additions & 0 deletions tests/Doctrine/Tests/Common/Annotations/DocLexerTest.php
Expand Up @@ -320,4 +320,9 @@ public function testTokenAdjacency(): void
self::assertFalse($lexer->nextTokenIsAdjacent());
self::assertFalse($lexer->moveNext());
}

public function testItReturnsNullWhenThereIsNothingToParse(): void
{
self::assertNull((new DocLexer())->peek());
}
}

0 comments on commit 9e034d7

Please sign in to comment.