Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a9749dc

Browse filesBrowse files
committed
fix resolve enum in string type resolver
1 parent cc1802d commit a9749dc
Copy full SHA for a9749dc

File tree

2 files changed

+9
-3
lines changed
Filter options

2 files changed

+9
-3
lines changed

‎src/Symfony/Component/TypeInfo/Tests/TypeResolver/StringTypeResolverTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/TypeInfo/Tests/TypeResolver/StringTypeResolverTest.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
use Symfony\Component\TypeInfo\Exception\UnsupportedException;
1717
use Symfony\Component\TypeInfo\Tests\Fixtures\AbstractDummy;
1818
use Symfony\Component\TypeInfo\Tests\Fixtures\Dummy;
19+
use Symfony\Component\TypeInfo\Tests\Fixtures\DummyBackedEnum;
1920
use Symfony\Component\TypeInfo\Tests\Fixtures\DummyCollection;
21+
use Symfony\Component\TypeInfo\Tests\Fixtures\DummyEnum;
2022
use Symfony\Component\TypeInfo\Tests\Fixtures\DummyWithTemplates;
2123
use Symfony\Component\TypeInfo\Type;
2224
use Symfony\Component\TypeInfo\TypeContext\TypeContext;
@@ -138,6 +140,8 @@ public static function resolveDataProvider(): iterable
138140
yield [Type::object(Dummy::class), 'static', $typeContextFactory->createFromClassName(Dummy::class, AbstractDummy::class)];
139141
yield [Type::object(AbstractDummy::class), 'parent', $typeContextFactory->createFromClassName(Dummy::class)];
140142
yield [Type::object(Dummy::class), 'Dummy', $typeContextFactory->createFromClassName(Dummy::class)];
143+
yield [Type::enum(DummyEnum::class), 'DummyEnum', $typeContextFactory->createFromClassName(DummyEnum::class)];
144+
yield [Type::enum(DummyBackedEnum::class), 'DummyBackedEnum', $typeContextFactory->createFromClassName(DummyBackedEnum::class)];
141145
yield [Type::template('T', Type::union(Type::int(), Type::string())), 'T', $typeContextFactory->createFromClassName(DummyWithTemplates::class)];
142146
yield [Type::template('V'), 'V', $typeContextFactory->createFromReflection(new \ReflectionMethod(DummyWithTemplates::class, 'getPrice'))];
143147

‎src/Symfony/Component/TypeInfo/TypeResolver/StringTypeResolver.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/TypeInfo/TypeResolver/StringTypeResolver.php
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ private function getTypeFromNode(TypeNode $node, ?TypeContext $typeContext): Typ
215215
};
216216
}
217217

218-
if ($type instanceof BuiltinType && $type->getTypeIdentifier() !== TypeIdentifier::ARRAY && $type->getTypeIdentifier() !== TypeIdentifier::ITERABLE) {
218+
if ($type instanceof BuiltinType && TypeIdentifier::ARRAY !== $type->getTypeIdentifier() && TypeIdentifier::ITERABLE !== $type->getTypeIdentifier()) {
219219
return $type;
220220
}
221221

@@ -246,14 +246,16 @@ private function resolveCustomIdentifier(string $identifier, ?TypeContext $typeC
246246
try {
247247
new \ReflectionClass($className);
248248
self::$classExistCache[$className] = true;
249-
250-
return Type::object($className);
251249
} catch (\Throwable) {
252250
}
253251
}
254252
}
255253

256254
if (self::$classExistCache[$className]) {
255+
if (is_subclass_of($className, \UnitEnum::class)) {
256+
return Type::enum($className);
257+
}
258+
257259
return Type::object($className);
258260
}
259261

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.