Skip to content

Commit

Permalink
generalize array based logic
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Jan 5, 2025
1 parent 9954344 commit 450b7b6
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Type/Php/ImplodeFunctionReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use function count;
use function implode;
use function in_array;
use const COUNT_RECURSIVE;

final class ImplodeFunctionReturnTypeExtension implements DynamicFunctionReturnTypeExtension
{
Expand Down Expand Up @@ -123,16 +124,16 @@ private function inferConstantType(ConstantArrayType $arrayType, ConstantStringT
$arrayValues[] = $constScalars;
}

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

$combinations = CombinationsHelper::combinations($arrayValues);
foreach ($combinations as $combination) {
$strings[] = new ConstantStringType(implode($separatorType->getValue(), $combination));
}
}

if (count($strings) > InitializerExprTypeResolver::CALCULATE_SCALARS_LIMIT) {
return null;
}

return TypeCombinator::union(...$strings);
}

Expand Down

0 comments on commit 450b7b6

Please sign in to comment.