diff --git a/composer.json b/composer.json index 47971b5cc..e322d82fc 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ "require": { "php": "^7.1 || ^8.0", "ext-tokenizer": "*", - "doctrine/lexer": "1.*", + "doctrine/lexer": "^1 || ^2", "psr/cache": "^1 || ^2 || ^3" }, "require-dev": { diff --git a/lib/Doctrine/Common/Annotations/DocLexer.php b/lib/Doctrine/Common/Annotations/DocLexer.php index f6567c512..7c0284b09 100644 --- a/lib/Doctrine/Common/Annotations/DocLexer.php +++ b/lib/Doctrine/Common/Annotations/DocLexer.php @@ -15,6 +15,8 @@ /** * Simple lexer for docblock annotations. + * + * @template-extends AbstractLexer */ final class DocLexer extends AbstractLexer { @@ -39,7 +41,7 @@ final class DocLexer extends AbstractLexer public const T_COLON = 112; public const T_MINUS = 113; - /** @var array */ + /** @var array */ protected $noCase = [ '@' => self::T_AT, ',' => self::T_COMMA, @@ -53,7 +55,7 @@ final class DocLexer extends AbstractLexer '\\' => self::T_NAMESPACE_SEPARATOR, ]; - /** @var array */ + /** @var array */ protected $withCase = [ 'true' => self::T_TRUE, 'false' => self::T_FALSE, @@ -126,4 +128,12 @@ protected function getType(&$value) return $type; } + + /** @return array{value: int|string, type:self::T_*|null, position:int} */ + public function peek(): array + { + $token = parent::peek(); + + return (array) $token; + } } diff --git a/phpstan.neon b/phpstan.neon index 4d2b2f1d3..40b25384a 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -22,3 +22,5 @@ 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 0df8a115a..c5c541984 100644 --- a/tests/Doctrine/Tests/Common/Annotations/DocLexerTest.php +++ b/tests/Doctrine/Tests/Common/Annotations/DocLexerTest.php @@ -19,9 +19,11 @@ public function testMarkerAnnotation(): void self::assertTrue($lexer->moveNext()); self::assertNull($lexer->token); + self::assertNotNull($lexer->lookahead); self::assertEquals('@', $lexer->lookahead['value']); self::assertTrue($lexer->moveNext()); + self::assertNotNull($lexer->token); self::assertEquals('@', $lexer->token['value']); self::assertEquals('Name', $lexer->lookahead['value']);