Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
klimick committed Aug 15, 2023
1 parent 1539518 commit d5bc652
Show file tree
Hide file tree
Showing 16 changed files with 26 additions and 1,350 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,7 @@ public static function analyze(
$toggled_class_exists = true;
}

$high_order_template_result = null;
$high_order_callable_info = $param
? HighOrderFunctionArgHandler::getCallableArgInfo($context, $arg->value, $statements_analyzer, $param)
: null;

if ($param && $high_order_callable_info) {
$high_order_template_result = HighOrderFunctionArgHandler::remapLowerBounds(
$statements_analyzer,
$template_result ?? new TemplateResult([], []),
$high_order_callable_info,
$param->type ?? Type::getMixed(),
);
} elseif (($arg->value instanceof PhpParser\Node\Expr\Closure
if (($arg->value instanceof PhpParser\Node\Expr\Closure
|| $arg->value instanceof PhpParser\Node\Expr\ArrowFunction)
&& $param
&& !$arg->value->getDocComment()
Expand All @@ -227,32 +215,14 @@ public static function analyze(
$was_inside_call = $context->inside_call;
$context->inside_call = true;

if (ExpressionAnalyzer::analyze(
$statements_analyzer,
$arg->value,
$context,
false,
null,
false,
$high_order_template_result,
) === false) {
if (ExpressionAnalyzer::analyze($statements_analyzer, $arg->value, $context) === false) {
$context->inside_call = $was_inside_call;

return false;
}

$context->inside_call = $was_inside_call;

if ($high_order_callable_info && $high_order_template_result) {
HighOrderFunctionArgHandler::enhanceCallableArgType(
$context,
$arg->value,
$statements_analyzer,
$high_order_callable_info,
$high_order_template_result,
);
}

if (($argument_offset === 0 && $method_id === 'array_filter' && count($args) === 2)
|| ($argument_offset > 0 && $method_id === 'array_map' && count($args) >= 2)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ class FunctionCallAnalyzer extends CallAnalyzer
public static function analyze(
StatementsAnalyzer $statements_analyzer,
PhpParser\Node\Expr\FuncCall $stmt,
Context $context,
?TemplateResult $template_result = null
Context $context
): bool {
$function_name = $stmt->name;

Expand Down Expand Up @@ -167,13 +166,11 @@ public static function analyze(
$set_inside_conditional = true;
}

if (!$template_result) {
$template_result = new TemplateResult([], []);
}

if (!$is_first_class_callable) {
$template_result = null;

if (isset($function_call_info->function_storage->template_types)) {
$template_result->template_types += $function_call_info->function_storage->template_types ?: [];
$template_result = new TemplateResult($function_call_info->function_storage->template_types ?: [], []);
}

ArgumentsAnalyzer::analyze(
Expand Down Expand Up @@ -209,8 +206,6 @@ public static function analyze(
}
}

$already_inferred_lower_bounds = $template_result->lower_bounds;

$template_result = new TemplateResult([], []);

// do this here to allow closure param checks
Expand All @@ -235,11 +230,6 @@ public static function analyze(
$function_call_info->function_id,
);

$template_result->lower_bounds = array_merge(
$template_result->lower_bounds,
$already_inferred_lower_bounds,
);

if ($function_name instanceof PhpParser\Node\Name && $function_call_info->function_id) {
$stmt_type = FunctionCallReturnTypeFetcher::fetch(
$statements_analyzer,
Expand Down
Loading

0 comments on commit d5bc652

Please sign in to comment.