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/phpstan.neon b/phpstan.neon index 40b25384a..4d2b2f1d3 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -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.*$#' 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()); + } }