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

Always keep FunctionLikeStorage->param_lookup in sync

This commit is contained in:
Claas Augner 2021-07-06 11:49:57 +02:00
parent 601a981898
commit b91e00b03f
3 changed files with 8 additions and 4 deletions

View File

@ -300,7 +300,6 @@ class Reflection
foreach ($params as $param) {
$param_array = $this->getReflectionParamData($param);
$storage->addParam($param_array);
$storage->param_lookup[$param->name] = true;
}
}

View File

@ -218,8 +218,7 @@ class FunctionLikeNodeScanner
}
$existing_params['$' . $param_storage->name] = $i;
$storage->param_lookup[$param_storage->name] = !!$param->type;
$storage->addParam($param_storage);
$storage->addParam($param_storage, !!$param->type);
if (!$param_storage->is_optional && !$param_storage->is_variadic) {
$required_param_count = $i + 1;

View File

@ -5,6 +5,8 @@ use Psalm\CodeLocation;
use Psalm\Internal\Analyzer\ClassLikeAnalyzer;
use Psalm\Type;
use function array_column;
use function array_fill_keys;
use function array_map;
use function implode;
@ -29,6 +31,7 @@ abstract class FunctionLikeStorage
public $params = [];
/**
* @psalm-readonly-allow-private-mutation
* @var array<string, bool>
*/
public $param_lookup = [];
@ -279,10 +282,13 @@ abstract class FunctionLikeStorage
public function setParams(array $params): void
{
$this->params = $params;
$param_names = array_column($params, 'name');
$this->param_lookup = array_fill_keys($param_names, true);
}
public function addParam(FunctionLikeParameter $param): void
public function addParam(FunctionLikeParameter $param, bool $lookup_value = null): void
{
$this->params[] = $param;
$this->param_lookup[$param->name] = $lookup_value ?? true;
}
}