Skip to content

Commit e8ca2ae

Browse files
committed
Extract OPTIONAL_KEYS_POWER_SET_LIMIT and FLATTEN_CONSTANT_ARRAYS_LIMIT
1 parent ef4fde5 commit e8ca2ae

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

src/Type/Constant/ConstantArrayType.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class ConstantArrayType implements Type
8484

8585
private const DESCRIBE_LIMIT = 8;
8686
private const CHUNK_FINITE_TYPES_LIMIT = 5;
87+
private const OPTIONAL_KEYS_POWER_SET_LIMIT = 10;
8788

8889
private TrinaryLogic $isList;
8990

@@ -232,7 +233,7 @@ public function getAllArrays(): array
232233
return $this->allArrays;
233234
}
234235

235-
if (count($this->optionalKeys) <= 10) {
236+
if (count($this->optionalKeys) <= self::OPTIONAL_KEYS_POWER_SET_LIMIT) {
236237
$optionalKeysCombinations = $this->powerSet($this->optionalKeys);
237238
} else {
238239
$optionalKeysCombinations = [

src/Type/TypeUtils.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
final class TypeUtils
2222
{
2323

24+
private const FLATTEN_CONSTANT_ARRAYS_LIMIT = 16384;
25+
2426
/**
2527
* @return list<ConstantIntegerType>
2628
*/
@@ -157,7 +159,7 @@ public static function flattenTypes(Type $type): array
157159
foreach ($constantArrays as $constantArray) {
158160
$optionalCount = count($constantArray->getOptionalKeys());
159161
$arrayCount = $optionalCount <= 20 ? (1 << $optionalCount) : PHP_INT_MAX;
160-
if ($arrayCount > 16384 || $estimatedCount > 16384 / max($arrayCount, 1)) {
162+
if ($arrayCount > self::FLATTEN_CONSTANT_ARRAYS_LIMIT || $estimatedCount > self::FLATTEN_CONSTANT_ARRAYS_LIMIT / max($arrayCount, 1)) {
161163
$bail = true;
162164
break;
163165
}

0 commit comments

Comments
 (0)