From aa8acf28f827a6ea7d65bcad81d3fa5b6eba8e55 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 16 Jan 2026 14:07:29 +0100 Subject: [PATCH 1/3] Simplify TypeCombinator->processArrayTypes() --- src/Type/TypeCombinator.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Type/TypeCombinator.php b/src/Type/TypeCombinator.php index b5db780c34..b5094f373e 100644 --- a/src/Type/TypeCombinator.php +++ b/src/Type/TypeCombinator.php @@ -838,15 +838,21 @@ private static function processArrayTypes(array $arrayTypes): array if (count($reducedArrayTypes) === 1) { return [self::intersect($reducedArrayTypes[0], ...$accessoryTypes)]; } - $scopes = []; + $useTemplateArray = true; + $templateArrayType = null; foreach ($arrayTypes as $arrayType) { if (!$arrayType instanceof TemplateArrayType) { $useTemplateArray = false; break; } - $scopes[$arrayType->getScope()->describe()] = $arrayType; + if ($templateArrayType !== null) { + $useTemplateArray = false; + break; + } + + $templateArrayType = $arrayType; } $arrayType = new ArrayType( @@ -854,15 +860,14 @@ private static function processArrayTypes(array $arrayTypes): array self::union(...self::optimizeConstantArrays($valueTypesForGeneralArray)), ); - if ($useTemplateArray && count($scopes) === 1) { - $templateArray = array_values($scopes)[0]; + if ($useTemplateArray && $templateArrayType !== null) { $arrayType = new TemplateArrayType( - $templateArray->getScope(), - $templateArray->getStrategy(), - $templateArray->getVariance(), - $templateArray->getName(), + $templateArrayType->getScope(), + $templateArrayType->getStrategy(), + $templateArrayType->getVariance(), + $templateArrayType->getName(), $arrayType, - $templateArray->getDefault(), + $templateArrayType->getDefault(), ); } From c813667b9c76e116e22a8fed7cd316ab7faa0c85 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 16 Jan 2026 14:11:07 +0100 Subject: [PATCH 2/3] Update TypeCombinator.php --- src/Type/TypeCombinator.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Type/TypeCombinator.php b/src/Type/TypeCombinator.php index b5094f373e..9680c512e2 100644 --- a/src/Type/TypeCombinator.php +++ b/src/Type/TypeCombinator.php @@ -839,17 +839,15 @@ private static function processArrayTypes(array $arrayTypes): array return [self::intersect($reducedArrayTypes[0], ...$accessoryTypes)]; } - $useTemplateArray = true; $templateArrayType = null; foreach ($arrayTypes as $arrayType) { if (!$arrayType instanceof TemplateArrayType) { - $useTemplateArray = false; + $templateArrayType = null; break; } if ($templateArrayType !== null) { - $useTemplateArray = false; - break; + continue; } $templateArrayType = $arrayType; @@ -860,7 +858,7 @@ private static function processArrayTypes(array $arrayTypes): array self::union(...self::optimizeConstantArrays($valueTypesForGeneralArray)), ); - if ($useTemplateArray && $templateArrayType !== null) { + if ($templateArrayType !== null) { $arrayType = new TemplateArrayType( $templateArrayType->getScope(), $templateArrayType->getStrategy(), From 296b395863116580a010df987885179661a360f0 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 16 Jan 2026 14:30:51 +0100 Subject: [PATCH 3/3] Prevent unnecessary array_values() --- src/Type/TypeCombinator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Type/TypeCombinator.php b/src/Type/TypeCombinator.php index 9680c512e2..2a05181311 100644 --- a/src/Type/TypeCombinator.php +++ b/src/Type/TypeCombinator.php @@ -1109,12 +1109,12 @@ private static function reduceArrays(array $constantArrays, bool $preserveTagged public static function intersect(Type ...$types): Type { - $types = array_values($types); - $typesCount = count($types); if ($typesCount === 0) { return new NeverType(); } + + $types = array_values($types); if ($typesCount === 1) { return $types[0]; }