Skip to content

Commit

Permalink
fix cleanup loop
Browse files Browse the repository at this point in the history
  • Loading branch information
malsuke committed Dec 26, 2024
1 parent 9c1a389 commit 8cb3030
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/Type/Php/PregSplitDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,33 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
return new ErrorType();
}

$limits = [];
if ($limitArg === null) {
$limits = [-1];
} else {
$limitType = $scope->getType($limitArg->value);
$limits = $limitType->getConstantScalarValues();
foreach ($limitType->getConstantScalarValues() as $limit) {
if (!is_int($limit)) {
return new ErrorType();
}
$limits[] = $limit;
}
}

$flags = [];
if ($flagArg === null) {
$flags = [0];
} else {
$flagType = $scope->getType($flagArg->value);
$flags = $flagType->getConstantScalarValues();
foreach ($flagType->getConstantScalarValues() as $flag) {
if (!is_int($flag)) {
return new ErrorType();
}
$flags[] = $flag;
}
}


if (count($patternConstantTypes) === 0 || count($subjectConstantTypes) === 0) {
$returnNonEmptyStrings = $flagArg !== null && $this->bitwiseFlagAnalyser->bitwiseOrContainsConstant($flagArg->value, $scope, 'PREG_SPLIT_NO_EMPTY')->yes();
if ($returnNonEmptyStrings) {
Expand Down Expand Up @@ -136,13 +149,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
foreach ($patternConstantTypes as $patternConstantType) {
foreach ($subjectConstantTypes as $subjectConstantType) {
foreach ($limits as $limit) {
if (!is_int($limit)) {
return null;
}
foreach ($flags as $flag) {
if (!is_int($flag)) {
return null;
}
$result = @preg_split($patternConstantType->getValue(), $subjectConstantType->getValue(), $limit, $flag);
if ($result === false) {
continue;
Expand Down

0 comments on commit 8cb3030

Please sign in to comment.