From bec0bba846d2d4a4703b6972dfc507b7b7f563ff Mon Sep 17 00:00:00 2001 From: Martin Herndl Date: Sat, 19 Apr 2025 20:59:05 +0200 Subject: [PATCH] Make constant array degradation to general array more DRY --- src/Type/Constant/ConstantArrayType.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) 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);