Skip to content

Commit 9ffae27

Browse files
committed
Make constant array degradation to general array more DRY
1 parent 7489a09 commit 9ffae27

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

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

+10-8
Original file line numberDiff line numberDiff line change
@@ -913,10 +913,7 @@ public function shiftArray(): Type
913913

914914
public function shuffleArray(): Type
915915
{
916-
$builder = ConstantArrayTypeBuilder::createFromConstantArray($this->getValuesArray());
917-
$builder->degradeToGeneralArray();
918-
919-
return $builder->getArray();
916+
return $this->getValuesArray()->degradeToGeneralArray();
920917
}
921918

922919
public function sliceArray(Type $offsetType, Type $lengthType, TrinaryLogic $preserveKeys): Type
@@ -937,10 +934,7 @@ public function sliceArray(Type $offsetType, Type $lengthType, TrinaryLogic $pre
937934
}
938935

939936
if ($offset === null || $length === null) {
940-
$builder = ConstantArrayTypeBuilder::createFromConstantArray($this);
941-
$builder->degradeToGeneralArray();
942-
943-
return $builder->getArray()
937+
return $this->degradeToGeneralArray()
944938
->sliceArray($offsetType, $lengthType, $preserveKeys);
945939
}
946940

@@ -1252,6 +1246,14 @@ public function generalizeValues(): self
12521246
return new self($this->keyTypes, $valueTypes, $this->nextAutoIndexes, $this->optionalKeys, $this->isList);
12531247
}
12541248

1249+
private function degradeToGeneralArray(): Type
1250+
{
1251+
$builder = ConstantArrayTypeBuilder::createFromConstantArray($this);
1252+
$builder->degradeToGeneralArray();
1253+
1254+
return $builder->getArray();
1255+
}
1256+
12551257
public function getKeysArray(): self
12561258
{
12571259
return $this->getKeysOrValuesArray($this->keyTypes);

0 commit comments

Comments
 (0)