Skip to content

Commit 325dcf0

Browse files
herndlmondrejmirtes
authored andcommitted
Simplify degradation to general array in ConstantArrayType::shuffle()
1 parent 2f282ef commit 325dcf0

File tree

1 file changed

+3
-16
lines changed

1 file changed

+3
-16
lines changed

Diff for: src/Type/Constant/ConstantArrayType.php

+3-16
Original file line numberDiff line numberDiff line change
@@ -913,23 +913,10 @@ public function shiftArray(): Type
913913

914914
public function shuffleArray(): Type
915915
{
916-
$valuesArray = $this->getValuesArray();
916+
$builder = ConstantArrayTypeBuilder::createFromConstantArray($this->getValuesArray());
917+
$builder->degradeToGeneralArray();
917918

918-
$isIterableAtLeastOnce = $valuesArray->isIterableAtLeastOnce();
919-
if ($isIterableAtLeastOnce->no()) {
920-
return $valuesArray;
921-
}
922-
923-
$generalizedArray = new ArrayType($valuesArray->getIterableKeyType(), $valuesArray->getIterableValueType());
924-
925-
if ($isIterableAtLeastOnce->yes()) {
926-
$generalizedArray = TypeCombinator::intersect($generalizedArray, new NonEmptyArrayType());
927-
}
928-
if ($valuesArray->isList->yes()) {
929-
$generalizedArray = TypeCombinator::intersect($generalizedArray, new AccessoryArrayListType());
930-
}
931-
932-
return $generalizedArray;
919+
return $builder->getArray();
933920
}
934921

935922
public function sliceArray(Type $offsetType, Type $lengthType, TrinaryLogic $preserveKeys): Type

0 commit comments

Comments
 (0)