Skip to content

Commit 2286f7b

Browse files
committed
Allow doctrine/lexer 2
It is still possible to avoid a BC-break while doing so.
1 parent 8708a31 commit 2286f7b

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"require": {
3535
"php": "^7.1 || ^8.0",
3636
"ext-tokenizer": "*",
37-
"doctrine/lexer": "1.*",
37+
"doctrine/lexer": "^1 || ^2",
3838
"psr/cache": "^1 || ^2 || ^3"
3939
},
4040
"require-dev": {

lib/Doctrine/Common/Annotations/DocLexer.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
/**
1717
* Simple lexer for docblock annotations.
18+
*
19+
* @template-extends AbstractLexer<DocLexer::T_*>
1820
*/
1921
final class DocLexer extends AbstractLexer
2022
{
@@ -39,7 +41,7 @@ final class DocLexer extends AbstractLexer
3941
public const T_COLON = 112;
4042
public const T_MINUS = 113;
4143

42-
/** @var array<string, int> */
44+
/** @var array<string, self::T*> */
4345
protected $noCase = [
4446
'@' => self::T_AT,
4547
',' => self::T_COMMA,
@@ -53,7 +55,7 @@ final class DocLexer extends AbstractLexer
5355
'\\' => self::T_NAMESPACE_SEPARATOR,
5456
];
5557

56-
/** @var array<string, int> */
58+
/** @var array<string, self::T*> */
5759
protected $withCase = [
5860
'true' => self::T_TRUE,
5961
'false' => self::T_FALSE,
@@ -126,4 +128,12 @@ protected function getType(&$value)
126128

127129
return $type;
128130
}
131+
132+
/** @return array{value: int|string, type:self::T_*|null, position:int} */
133+
public function peek(): array
134+
{
135+
$token = parent::peek();
136+
137+
return (array) $token;
138+
}
129139
}

phpstan.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ parameters:
2222

2323
# That tag is empty on purpose
2424
- '#PHPDoc tag @var has invalid value \(\)\: Unexpected token "\*/", expected type at offset 9#'
25+
# Backwards-compatibility
26+
- '#^Return type.*of method.*DocLexer::peek.*should be compatible.*$#'

tests/Doctrine/Tests/Common/Annotations/DocLexerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ public function testMarkerAnnotation(): void
1919

2020
self::assertTrue($lexer->moveNext());
2121
self::assertNull($lexer->token);
22+
self::assertNotNull($lexer->lookahead);
2223
self::assertEquals('@', $lexer->lookahead['value']);
2324

2425
self::assertTrue($lexer->moveNext());
26+
self::assertNotNull($lexer->token);
2527
self::assertEquals('@', $lexer->token['value']);
2628
self::assertEquals('Name', $lexer->lookahead['value']);
2729

0 commit comments

Comments
 (0)