Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed May 31, 2024
1 parent 11341ca commit b24c9f8
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Type/Php/ArrayFilterFunctionReturnTypeReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,13 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
} elseif ($callbackArg instanceof ArrowFunction && count($callbackArg->params) > 0) {
return $this->filterByTruthyValue($scope, null, $arrayArgType, $callbackArg->params[0]->var, $callbackArg->expr);
} elseif ($callbackArg instanceof String_) {
$funcName = self::createFunctionName($callbackArg->value);
if ($funcName === null) {
return new ErrorType();
}

$keyVar = new Variable('key');
$expr = new FuncCall(self::createFunctionName($callbackArg->value), [new Arg($keyVar)]);
$expr = new FuncCall($funcName, [new Arg($keyVar)]);
return $this->filterByTruthyValue($scope, null, $arrayArgType, $keyVar, $expr);
}
}
Expand All @@ -121,9 +126,14 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
} elseif ($callbackArg instanceof ArrowFunction && count($callbackArg->params) > 0) {
return $this->filterByTruthyValue($scope, $callbackArg->params[0]->var, $arrayArgType, $callbackArg->params[1]->var ?? null, $callbackArg->expr);
} elseif ($callbackArg instanceof String_) {
$funcName = self::createFunctionName($callbackArg->value);
if ($funcName === null) {
return new ErrorType();
}

$itemVar = new Variable('item');
$keyVar = new Variable('key');
$expr = new FuncCall(self::createFunctionName($callbackArg->value), [new Arg($itemVar), new Arg($keyVar)]);
$expr = new FuncCall($funcName, [new Arg($itemVar), new Arg($keyVar)]);
return $this->filterByTruthyValue($scope, $itemVar, $arrayArgType, $keyVar, $expr);
}
}
Expand Down

0 comments on commit b24c9f8

Please sign in to comment.