Skip to content

Commit

Permalink
[TypeProvider] Provide argument types during FunctionParamsProviderEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
veewee committed Jan 21, 2022
1 parent f6369dc commit 6b789bb
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 36 deletions.
Expand Up @@ -1291,6 +1291,7 @@ private static function evaluateArbitraryParam(
|| $arg->value instanceof PhpParser\Node\Expr\FuncCall
|| $arg->value instanceof PhpParser\Node\Expr\MethodCall
|| $arg->value instanceof PhpParser\Node\Expr\StaticCall
|| $arg->value instanceof PhpParser\Node\Expr\ArrowFunction
|| $arg->value instanceof PhpParser\Node\Expr\New_
|| $arg->value instanceof PhpParser\Node\Expr\Cast
|| $arg->value instanceof PhpParser\Node\Expr\Assign
Expand Down
Expand Up @@ -528,51 +528,58 @@ private static function handleNamedFunction(
$args = $stmt->isFirstClassCallable() ? [] : $stmt->getArgs();

if ($function_call_info->function_exists) {
if (!$function_call_info->in_call_map || $function_call_info->is_stubbed) {
try {
$function_call_info->function_storage = $function_storage = $codebase_functions->getStorage(
$statements_analyzer,
strtolower($function_call_info->function_id)
);

$function_call_info->function_params = $function_call_info->function_storage->params;

if (!$function_storage->allow_named_arg_calls) {
$function_call_info->allow_named_args = false;
}

if (!$is_predefined) {
$function_call_info->defined_constants = $function_storage->defined_constants;
$function_call_info->global_variables = $function_storage->global_variables;
}
} catch (UnexpectedValueException $e) {
$function_call_info->function_params = [
new FunctionLikeParameter('args', false, null, null, null, false, false, true)
];
}
} else {
$function_callable = InternalCallMapHandler::getCallableFromCallMapById(
$codebase,
$function_call_info->function_id,
$args,
$statements_analyzer->node_data
);

$function_call_info->function_params = $function_callable->params;
}

if ($codebase->functions->params_provider->has($function_call_info->function_id)) {
ArgumentsAnalyzer::analyze(
$statements_analyzer,
$stmt->getArgs(),
$function_call_info->function_params,
$function_call_info->function_id,
$function_call_info->allow_named_args,
$context
);

$function_call_info->function_params = $codebase->functions->params_provider->getFunctionParams(
$statements_analyzer,
$function_call_info->function_id,
$args,
null,
$context,
$code_location
);
}

if ($function_call_info->function_params === null) {
if (!$function_call_info->in_call_map || $function_call_info->is_stubbed) {
try {
$function_call_info->function_storage = $function_storage = $codebase_functions->getStorage(
$statements_analyzer,
strtolower($function_call_info->function_id)
);

$function_call_info->function_params = $function_call_info->function_storage->params;

if (!$function_storage->allow_named_arg_calls) {
$function_call_info->allow_named_args = false;
}

if (!$is_predefined) {
$function_call_info->defined_constants = $function_storage->defined_constants;
$function_call_info->global_variables = $function_storage->global_variables;
}
} catch (UnexpectedValueException $e) {
$function_call_info->function_params = [
new FunctionLikeParameter('args', false, null, null, null, false, false, true)
];
}
} else {
$function_callable = InternalCallMapHandler::getCallableFromCallMapById(
$codebase,
$function_call_info->function_id,
$args,
$statements_analyzer->node_data
);

$function_call_info->function_params = $function_callable->params;
}
}

if ($codebase->store_node_types
&& !$context->collect_initializations
&& !$context->collect_mutations
Expand Down

0 comments on commit 6b789bb

Please sign in to comment.