1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 12:55:26 +01:00

Simplify dynamic storage handling in FunctionCallAnalyzer

This commit is contained in:
adrew 2022-01-24 12:10:07 +03:00
parent a4e56ae288
commit 89c6a70dda

View File

@ -526,7 +526,7 @@ class FunctionCallAnalyzer extends CallAnalyzer
$function_call_info->defined_constants = [];
$function_call_info->global_variables = [];
$args = $stmt->isFirstClassCallable() ? [] : $stmt->getArgs();
$has_dynamic_storage = false;
$dynamic_function_storage = null;
if ($codebase->functions->dynamic_storage_provider->has($function_call_info->function_id)) {
$dynamic_function_storage = $codebase->functions->dynamic_storage_provider->getFunctionStorage(
@ -536,52 +536,46 @@ class FunctionCallAnalyzer extends CallAnalyzer
$context,
$code_location
);
if ($dynamic_function_storage) {
$has_dynamic_storage = true;
$function_call_info->function_storage = $dynamic_function_storage;
$function_call_info->function_params = $function_call_info->function_storage->params;
$function_call_info->allow_named_args = $dynamic_function_storage->allow_named_arg_calls;
$function_call_info->defined_constants = $dynamic_function_storage->defined_constants;
$function_call_info->global_variables = $dynamic_function_storage->global_variables;
}
}
if ($function_call_info->function_exists) {
if (!$has_dynamic_storage) {
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
if ($dynamic_function_storage) {
$function_call_info->function_storage = $dynamic_function_storage;
$function_call_info->function_params = $dynamic_function_storage->params;
$function_call_info->allow_named_args = $dynamic_function_storage->allow_named_arg_calls;
$function_call_info->defined_constants = $dynamic_function_storage->defined_constants;
$function_call_info->global_variables = $dynamic_function_storage->global_variables;
} elseif (!$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_callable->params;
$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)) {