Skip to content

Commit c4dc01c

Browse files
committed
Update ConstantArrayType.php
1 parent 4277198 commit c4dc01c

File tree

1 file changed

+10
-25
lines changed

1 file changed

+10
-25
lines changed

src/Type/Constant/ConstantArrayType.php

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -746,17 +746,14 @@ public function setExistingOffsetValueType(Type $offsetType, Type $valueType): T
746746
return $builder->getArray();
747747
}
748748

749-
/**
750-
* @return list<ConstantIntegerType|ConstantStringType>|null
751-
*/
749+
/** @return array<ConstantIntegerType|ConstantStringType>|null */
752750
private function resolveFiniteScalarKeyTypes(Type $offsetType): ?array
753751
{
754-
$offsetType = $offsetType->toArrayKey();
752+
$result = [];
755753

756-
// Handle unions of constant string types (e.g. 'a'|'b')
754+
$offsetType = $offsetType->toArrayKey();
757755
$constantStrings = $offsetType->getConstantStrings();
758-
if (count($constantStrings) >= 2 && count($constantStrings) <= self::CHUNK_FINITE_TYPES_LIMIT) {
759-
$result = [];
756+
if (count($constantStrings) > 0) {
760757
foreach ($constantStrings as $constantString) {
761758
$scalarValues = $constantString->getConstantScalarValues();
762759
if (count($scalarValues) !== 1) {
@@ -770,34 +767,22 @@ private function resolveFiniteScalarKeyTypes(Type $offsetType): ?array
770767
return null;
771768
}
772769
}
773-
return $result;
774-
}
775-
776-
// Handle integer range types (e.g. int<1,5>)
777-
$integerRanges = TypeUtils::getIntegerRanges($offsetType);
778-
if (count($integerRanges) > 0) {
779-
$finiteScalarTypes = [];
780-
$seen = [];
770+
} else {
771+
$integerRanges = TypeUtils::getIntegerRanges($offsetType);
781772
foreach ($integerRanges as $integerRange) {
782773
$finiteTypes = $integerRange->getFiniteTypes();
783774
if ($finiteTypes === []) {
784775
return null;
785776
}
786777

787778
foreach ($finiteTypes as $finiteType) {
788-
if (isset($seen[$finiteType->getValue()])) {
789-
continue;
790-
}
791-
$seen[$finiteType->getValue()] = true;
792-
$finiteScalarTypes[] = $finiteType;
779+
$result[$finiteType->getValue()] = $finiteType;
793780
}
794781
}
782+
}
795783

796-
if (count($finiteScalarTypes) < 2 || count($finiteScalarTypes) > self::CHUNK_FINITE_TYPES_LIMIT) {
797-
return null;
798-
}
799-
800-
return $finiteScalarTypes;
784+
if (count($result) >= 2 && count($result) <= self::CHUNK_FINITE_TYPES_LIMIT) {
785+
return $result;
801786
}
802787

803788
return null;

0 commit comments

Comments
 (0)