Skip to content

Commit 7131e07

Browse files
committed
Make constant array degradation to general array more DRY
1 parent ea816fc commit 7131e07

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/Type/Constant/ConstantArrayType.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -919,10 +919,7 @@ public function shiftArray(): Type
919919

920920
public function shuffleArray(): Type
921921
{
922-
$builder = ConstantArrayTypeBuilder::createFromConstantArray($this->getValuesArray());
923-
$builder->degradeToGeneralArray();
924-
925-
return $builder->getArray();
922+
return $this->getValuesArray()->degradeToGeneralArray();
926923
}
927924

928925
public function sliceArray(Type $offsetType, Type $lengthType, TrinaryLogic $preserveKeys): Type
@@ -943,10 +940,7 @@ public function sliceArray(Type $offsetType, Type $lengthType, TrinaryLogic $pre
943940
}
944941

945942
if ($offset === null || $length === null) {
946-
$builder = ConstantArrayTypeBuilder::createFromConstantArray($this);
947-
$builder->degradeToGeneralArray();
948-
949-
return $builder->getArray()
943+
return $this->degradeToGeneralArray()
950944
->sliceArray($offsetType, $lengthType, $preserveKeys);
951945
}
952946

@@ -1268,6 +1262,14 @@ public function generalizeValues(): self
12681262
return new self($this->keyTypes, $valueTypes, $this->nextAutoIndexes, $this->optionalKeys, $this->isList);
12691263
}
12701264

1265+
private function degradeToGeneralArray(): Type
1266+
{
1267+
$builder = ConstantArrayTypeBuilder::createFromConstantArray($this);
1268+
$builder->degradeToGeneralArray();
1269+
1270+
return $builder->getArray();
1271+
}
1272+
12711273
public function getKeysArray(): self
12721274
{
12731275
return $this->getKeysOrValuesArray($this->keyTypes);

0 commit comments

Comments
 (0)