Skip to content

Commit

Permalink
Merge pull request #460 from greg0ire/allow-lexer-2
Browse files Browse the repository at this point in the history
Allow doctrine/lexer 2
  • Loading branch information
greg0ire committed Dec 11, 2022
2 parents 8708a31 + 2286f7b commit 23bf490
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -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": {
Expand Down
14 changes: 12 additions & 2 deletions lib/Doctrine/Common/Annotations/DocLexer.php
Expand Up @@ -15,6 +15,8 @@

/**
* Simple lexer for docblock annotations.
*
* @template-extends AbstractLexer<DocLexer::T_*>
*/
final class DocLexer extends AbstractLexer
{
Expand All @@ -39,7 +41,7 @@ final class DocLexer extends AbstractLexer
public const T_COLON = 112;
public const T_MINUS = 113;

/** @var array<string, int> */
/** @var array<string, self::T*> */
protected $noCase = [
'@' => self::T_AT,
',' => self::T_COMMA,
Expand All @@ -53,7 +55,7 @@ final class DocLexer extends AbstractLexer
'\\' => self::T_NAMESPACE_SEPARATOR,
];

/** @var array<string, int> */
/** @var array<string, self::T*> */
protected $withCase = [
'true' => self::T_TRUE,
'false' => self::T_FALSE,
Expand Down Expand Up @@ -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;
}
}
2 changes: 2 additions & 0 deletions phpstan.neon
Expand Up @@ -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.*$#'
2 changes: 2 additions & 0 deletions tests/Doctrine/Tests/Common/Annotations/DocLexerTest.php
Expand Up @@ -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']);

Expand Down

0 comments on commit 23bf490

Please sign in to comment.