From 32d72bbc1ed313c9ff650a50fe83bd6eb33042fe Mon Sep 17 00:00:00 2001 From: Martin Herndl Date: Fri, 18 Apr 2025 21:17:59 +0200 Subject: [PATCH] Simplify degradation to general array in `ConstantArrayType::shuffle()` --- src/Type/Constant/ConstantArrayType.php | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/src/Type/Constant/ConstantArrayType.php b/src/Type/Constant/ConstantArrayType.php index 76fdf42a5d..a44135424c 100644 --- a/src/Type/Constant/ConstantArrayType.php +++ b/src/Type/Constant/ConstantArrayType.php @@ -913,23 +913,10 @@ public function shiftArray(): Type public function shuffleArray(): Type { - $valuesArray = $this->getValuesArray(); + $builder = ConstantArrayTypeBuilder::createFromConstantArray($this->getValuesArray()); + $builder->degradeToGeneralArray(); - $isIterableAtLeastOnce = $valuesArray->isIterableAtLeastOnce(); - if ($isIterableAtLeastOnce->no()) { - return $valuesArray; - } - - $generalizedArray = new ArrayType($valuesArray->getIterableKeyType(), $valuesArray->getIterableValueType()); - - if ($isIterableAtLeastOnce->yes()) { - $generalizedArray = TypeCombinator::intersect($generalizedArray, new NonEmptyArrayType()); - } - if ($valuesArray->isList->yes()) { - $generalizedArray = TypeCombinator::intersect($generalizedArray, new AccessoryArrayListType()); - } - - return $generalizedArray; + return $builder->getArray(); } public function sliceArray(Type $offsetType, Type $lengthType, TrinaryLogic $preserveKeys): Type