From 41872011b1bd6b4037e7653972334e5b707ab82c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomas=20Nork=C5=ABnas?= Date: Tue, 1 Jul 2025 13:20:44 +0300 Subject: [PATCH] [TypeInfo] Reuse `CollectionType::mergeCollectionValueTypes` for `ConstFetchNode` --- .../TypeResolver/StringTypeResolverTest.php | 8 +++---- .../TypeResolver/StringTypeResolver.php | 22 ++----------------- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/src/Symfony/Component/TypeInfo/Tests/TypeResolver/StringTypeResolverTest.php b/src/Symfony/Component/TypeInfo/Tests/TypeResolver/StringTypeResolverTest.php index 3b194128661c9..cca88b552acfd 100644 --- a/src/Symfony/Component/TypeInfo/Tests/TypeResolver/StringTypeResolverTest.php +++ b/src/Symfony/Component/TypeInfo/Tests/TypeResolver/StringTypeResolverTest.php @@ -103,12 +103,12 @@ public static function resolveDataProvider(): iterable yield [Type::int(), DummyWithConstants::class.'::DUMMY_INT_*']; yield [Type::int(), DummyWithConstants::class.'::DUMMY_INT_A']; yield [Type::float(), DummyWithConstants::class.'::DUMMY_FLOAT_*']; - yield [Type::bool(), DummyWithConstants::class.'::DUMMY_TRUE_*']; - yield [Type::bool(), DummyWithConstants::class.'::DUMMY_FALSE_*']; + yield [Type::true(), DummyWithConstants::class.'::DUMMY_TRUE_*']; + yield [Type::false(), DummyWithConstants::class.'::DUMMY_FALSE_*']; yield [Type::null(), DummyWithConstants::class.'::DUMMY_NULL_*']; - yield [Type::array(), DummyWithConstants::class.'::DUMMY_ARRAY_*']; + yield [Type::array(null, Type::union(Type::int(), Type::string())), DummyWithConstants::class.'::DUMMY_ARRAY_*']; yield [Type::enum(DummyEnum::class, Type::string()), DummyWithConstants::class.'::DUMMY_ENUM_*']; - yield [Type::union(Type::string(), Type::int(), Type::float(), Type::bool(), Type::null(), Type::array(), Type::enum(DummyEnum::class, Type::string())), DummyWithConstants::class.'::DUMMY_MIX_*']; + yield [Type::union(Type::enum(DummyEnum::class, Type::string()), Type::array(Type::mixed(), Type::union(Type::int(), Type::string())), Type::string(), Type::int(), Type::float(), Type::bool(), Type::null()), DummyWithConstants::class.'::DUMMY_MIX_*']; // identifiers yield [Type::bool(), 'bool']; diff --git a/src/Symfony/Component/TypeInfo/TypeResolver/StringTypeResolver.php b/src/Symfony/Component/TypeInfo/TypeResolver/StringTypeResolver.php index 844de98963e3d..1ae865e783eb1 100644 --- a/src/Symfony/Component/TypeInfo/TypeResolver/StringTypeResolver.php +++ b/src/Symfony/Component/TypeInfo/TypeResolver/StringTypeResolver.php @@ -149,29 +149,11 @@ private function getTypeFromNode(TypeNode $node, ?TypeContext $typeContext): Typ foreach ((new \ReflectionClass($className))->getReflectionConstants() as $const) { if (preg_match('/^'.str_replace('\*', '.*', preg_quote($node->constExpr->name, '/')).'$/', $const->getName())) { - $constValue = $const->getValue(); - - $types[] = match (true) { - true === $constValue, - false === $constValue => Type::bool(), - null === $constValue => Type::null(), - \is_string($constValue) => Type::string(), - \is_int($constValue) => Type::int(), - \is_float($constValue) => Type::float(), - \is_array($constValue) => Type::array(), - $constValue instanceof \UnitEnum => Type::enum($constValue::class), - default => Type::mixed(), - }; + $types[] = Type::fromValue($const->getValue()); } } - $types = array_unique($types); - - if (\count($types) > 2) { - return Type::union(...$types); - } - - return $types[0] ?? Type::null(); + return CollectionType::mergeCollectionValueTypes($types); } return match ($node->constExpr::class) { 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