1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-04 10:38:49 +01:00

only put offset to 0 when there's only one argument

This commit is contained in:
orklah 2021-10-07 20:38:10 +02:00
parent 22fb4b5d19
commit 87a5df6043

View File

@ -131,6 +131,7 @@ class ArrayFunctionArgumentsAnalyzer
string $method_id
): ?bool {
$array_arg = $args[0]->value;
$nb_args = count($args);
$unpacked_args = array_filter(
$args,
@ -140,7 +141,7 @@ class ArrayFunctionArgumentsAnalyzer
);
if ($method_id === 'array_push' && !$unpacked_args) {
for ($i = 1, $iMax = count($args); $i < $iMax; $i++) {
for ($i = 1; $i < $nb_args; $i++) {
$was_inside_assignment = $context->inside_assignment;
$context->inside_assignment = true;
@ -187,7 +188,7 @@ class ArrayFunctionArgumentsAnalyzer
return false;
}
for ($i = 1, $iMax = count($args); $i < $iMax; $i++) {
for ($i = 1; $i < $nb_args; $i++) {
if (ExpressionAnalyzer::analyze(
$statements_analyzer,
$args[$i]->value,
@ -239,7 +240,7 @@ class ArrayFunctionArgumentsAnalyzer
return false;
}
if ($method_id === 'array_unshift') {
if ($method_id === 'array_unshift' && $nb_args === 2 && !$unpacked_args) {
$new_offset_type = Type::getInt(false, 0);
} else {
$new_offset_type = Type::getInt();