diff --git a/lib/Doctrine/Common/Annotations/DocLexer.php b/lib/Doctrine/Common/Annotations/DocLexer.php index 7c0284b09..dbf60c0d5 100644 --- a/lib/Doctrine/Common/Annotations/DocLexer.php +++ b/lib/Doctrine/Common/Annotations/DocLexer.php @@ -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; } } diff --git a/tests/Doctrine/Tests/Common/Annotations/DocLexerTest.php b/tests/Doctrine/Tests/Common/Annotations/DocLexerTest.php index c5c541984..d32b6ad89 100644 --- a/tests/Doctrine/Tests/Common/Annotations/DocLexerTest.php +++ b/tests/Doctrine/Tests/Common/Annotations/DocLexerTest.php @@ -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()); + } }