diff --git a/src/Type/Constant/ConstantArrayType.php b/src/Type/Constant/ConstantArrayType.php index 8e76f0d08f..678510e87e 100644 --- a/src/Type/Constant/ConstantArrayType.php +++ b/src/Type/Constant/ConstantArrayType.php @@ -913,10 +913,7 @@ public function shiftArray(): Type public function shuffleArray(): Type { - $builder = ConstantArrayTypeBuilder::createFromConstantArray($this->getValuesArray()); - $builder->degradeToGeneralArray(); - - return $builder->getArray(); + return $this->getValuesArray()->degradeToGeneralArray(); } public function sliceArray(Type $offsetType, Type $lengthType, TrinaryLogic $preserveKeys): Type @@ -937,10 +934,7 @@ public function sliceArray(Type $offsetType, Type $lengthType, TrinaryLogic $pre } if ($offset === null || $length === null) { - $builder = ConstantArrayTypeBuilder::createFromConstantArray($this); - $builder->degradeToGeneralArray(); - - return $builder->getArray() + return $this->degradeToGeneralArray() ->sliceArray($offsetType, $lengthType, $preserveKeys); } @@ -1252,6 +1246,14 @@ public function generalizeValues(): self return new self($this->keyTypes, $valueTypes, $this->nextAutoIndexes, $this->optionalKeys, $this->isList); } + private function degradeToGeneralArray(): Type + { + $builder = ConstantArrayTypeBuilder::createFromConstantArray($this); + $builder->degradeToGeneralArray(); + + return $builder->getArray(); + } + public function getKeysArray(): self { return $this->getKeysOrValuesArray($this->keyTypes);