Skip to content

Commit 6052ad5

Browse files
committed
Support literal<T> in PhpDocTypeReflector
1 parent 820867b commit 6052ad5

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/Reflection/Internal/PhpDoc/PhpDocTypeReflector.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ private function reflectIdentifier(string $name, array $genericNodes = []): Type
185185
'literal-int' => types::literalInt,
186186
'literal-string' => types::literalString,
187187
'literal-float' => types::literalFloat,
188+
'literal' => match ($number = \count($typeArguments)) {
189+
1 => types::literal($typeArguments[0]),
190+
default => throw new InvalidPhpDocType(\sprintf('literal type should have 1 type argument, got %d', $number)),
191+
},
188192
'callable-string' => types::callableString(),
189193
'interface-string', 'enum-string', 'trait-string' => types::classString,
190194
'callable-array' => types::callableArray(),

tests/Reflection/Internal/PhpDoc/PhpDocTypeReflectorTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ private static function validTypes(): \Generator
8181
yield ['closed-resource', types::resource];
8282
yield ['open-resource', types::resource];
8383
yield ['array-key', types::arrayKey];
84+
yield ['literal', new InvalidPhpDocType('literal type should have 1 type argument, got 0')];
85+
yield ['literal<string>', types::literal(types::string)];
86+
yield ['literal<int, string>', new InvalidPhpDocType('literal type should have 1 type argument, got 2')];
8487
yield ['mixed', types::mixed];
8588
yield ['list', types::list()];
8689
yield ['list<mixed>', types::list()];

0 commit comments

Comments
 (0)