1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Extract FunctionLikeStorage::setParams()/addParam()

This commit is contained in:
Claas Augner 2021-07-06 11:46:51 +02:00
parent 9acbb6061e
commit 601a981898
4 changed files with 23 additions and 9 deletions

View File

@ -280,7 +280,7 @@ class Reflection
$callables = InternalCallMapHandler::getCallablesFromCallMap($method_id);
if ($callables && $callables[0]->params !== null && $callables[0]->return_type !== null) {
$storage->params = [];
$storage->setParams([]);
foreach ($callables[0]->params as $param) {
if ($param->type) {
@ -288,18 +288,18 @@ class Reflection
}
}
$storage->params = $callables[0]->params;
$storage->setParams($callables[0]->params);
$storage->return_type = $callables[0]->return_type;
$storage->return_type->queueClassLikesForScanning($this->codebase);
} else {
$params = $method->getParameters();
$storage->params = [];
$storage->setParams([]);
foreach ($params as $param) {
$param_array = $this->getReflectionParamData($param);
$storage->params[] = $param_array;
$storage->addParam($param_array);
$storage->param_lookup[$param->name] = true;
}
}
@ -367,14 +367,14 @@ class Reflection
&& $callmap_callable->params !== null
&& $callmap_callable->return_type !== null
) {
$storage->params = $callmap_callable->params;
$storage->setParams($callmap_callable->params);
$storage->return_type = $callmap_callable->return_type;
} else {
$reflection_params = $reflection_function->getParameters();
foreach ($reflection_params as $param) {
$param_obj = $this->getReflectionParamData($param);
$storage->params[] = $param_obj;
$storage->addParam($param_obj);
}
if ($reflection_return_type = $reflection_function->getReturnType()) {

View File

@ -678,7 +678,7 @@ class FunctionLikeDocblockScanner
null
);
$storage->params[] = $storage_param;
$storage->addParam($storage_param);
}
try {

View File

@ -169,7 +169,7 @@ class FunctionLikeNodeScanner
$has_optional_param = false;
$existing_params = [];
$storage->params = [];
$storage->setParams([]);
foreach ($stmt->getParams() as $param) {
if ($param->var instanceof PhpParser\Node\Expr\Error) {
@ -219,7 +219,7 @@ class FunctionLikeNodeScanner
$existing_params['$' . $param_storage->name] = $i;
$storage->param_lookup[$param_storage->name] = !!$param->type;
$storage->params[] = $param_storage;
$storage->addParam($param_storage);
if (!$param_storage->is_optional && !$param_storage->is_variadic) {
$required_param_count = $i + 1;

View File

@ -23,6 +23,7 @@ abstract class FunctionLikeStorage
public $stmt_location;
/**
* @psalm-readonly-allow-private-mutation
* @var list<FunctionLikeParameter>
*/
public $params = [];
@ -271,4 +272,17 @@ abstract class FunctionLikeStorage
return $visibility_text . ' ' . $symbol_text;
}
/**
* @param list<FunctionLikeParameter> $params
*/
public function setParams(array $params): void
{
$this->params = $params;
}
public function addParam(FunctionLikeParameter $param): void
{
$this->params[] = $param;
}
}