Skip to content

Commit f161750

Browse files
committed
fix combinations count
1 parent 06ca776 commit f161750

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Diff for: src/Type/Php/ImplodeFunctionReturnTypeExtension.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
use function count;
2323
use function implode;
2424
use function in_array;
25-
use const COUNT_RECURSIVE;
2625

2726
final class ImplodeFunctionReturnTypeExtension implements DynamicFunctionReturnTypeExtension
2827
{
@@ -116,15 +115,17 @@ private function inferConstantType(ConstantArrayType $arrayType, ConstantStringT
116115
$valueTypes = $array->getValueTypes();
117116

118117
$arrayValues = [];
118+
$combinationsCount = 1;
119119
foreach ($valueTypes as $valueType) {
120120
$constScalars = $valueType->getConstantScalarValues();
121121
if (count($constScalars) === 0) {
122122
return null;
123123
}
124124
$arrayValues[] = $constScalars;
125+
$combinationsCount *= count($constScalars);
125126
}
126127

127-
if (count($strings) + count($arrayValues, COUNT_RECURSIVE) > InitializerExprTypeResolver::CALCULATE_SCALARS_LIMIT) {
128+
if ($combinationsCount > InitializerExprTypeResolver::CALCULATE_SCALARS_LIMIT) {
128129
return null;
129130
}
130131

@@ -134,6 +135,10 @@ private function inferConstantType(ConstantArrayType $arrayType, ConstantStringT
134135
}
135136
}
136137

138+
if (count($strings) > InitializerExprTypeResolver::CALCULATE_SCALARS_LIMIT) {
139+
return null;
140+
}
141+
137142
return TypeCombinator::union(...$strings);
138143
}
139144

0 commit comments

Comments
 (0)