Skip to content

Commit a0cdd3f

Browse files
norkunasxabbuh
authored andcommitted
[TypeInfo] Fix Type::fromValue incorrectly setting object type instead of enum
1 parent e06b10c commit a0cdd3f

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/Symfony/Component/TypeInfo/Tests/TypeFactoryTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ public static function createFromValueProvider(): iterable
254254
yield [Type::object(\DateTimeImmutable::class), new \DateTimeImmutable()];
255255
yield [Type::object(), new \stdClass()];
256256
yield [Type::list(Type::object()), [new \stdClass(), new \DateTimeImmutable()]];
257+
yield [Type::enum(DummyEnum::class), DummyEnum::ONE];
258+
yield [Type::enum(DummyBackedEnum::class), DummyBackedEnum::ONE];
257259

258260
// collection
259261
$arrayAccess = new class implements \ArrayAccess {

src/Symfony/Component/TypeInfo/TypeFactoryTrait.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ public static function fromValue(mixed $value): Type
412412
}
413413

414414
$type = match (true) {
415+
\is_object($value) && is_subclass_of($value::class, \UnitEnum::class) => Type::enum($value::class),
415416
\is_object($value) => \stdClass::class === $value::class ? self::object() : self::object($value::class),
416417
\is_array($value) => self::builtin(TypeIdentifier::ARRAY),
417418
default => null,
@@ -428,8 +429,6 @@ public static function fromValue(mixed $value): Type
428429
/** @var list<Type> $valueTypes */
429430
$valueTypes = [];
430431

431-
$i = 0;
432-
433432
foreach ($value as $k => $v) {
434433
$keyTypes[] = self::fromValue($k);
435434
$valueTypes[] = self::fromValue($v);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy