Skip to content

Commit

Permalink
fix combinations count
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Jan 5, 2025
1 parent 06ca776 commit 29caa26
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Type/Php/ImplodeFunctionReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use function count;
use function implode;
use function in_array;
use const COUNT_RECURSIVE;

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

$arrayValues = [];
$combinationsCount = 1;
foreach ($valueTypes as $valueType) {
$constScalars = $valueType->getConstantScalarValues();
if (count($constScalars) === 0) {
return null;
}
$arrayValues[] = $constScalars;
$combinationsCount *= count($constScalars);
}

if (count($strings) + count($arrayValues, COUNT_RECURSIVE) > InitializerExprTypeResolver::CALCULATE_SCALARS_LIMIT) {
if ($combinationsCount > InitializerExprTypeResolver::CALCULATE_SCALARS_LIMIT) {
return null;
}

Expand Down

0 comments on commit 29caa26

Please sign in to comment.