Skip to content

Commit

Permalink
ArgumentsNormalizer - skip unused arguments in non-variadic signature…
Browse files Browse the repository at this point in the history
…s, still return a normalized call
  • Loading branch information
ondrejmirtes committed Feb 15, 2024
1 parent cfedc7b commit 17e5bac
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/Analyser/ArgumentsNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private static function reorderArgs(ParametersAcceptor $parametersAcceptor, Call
);
} else {
if (!$hasVariadic) {
return null;
continue;
}

$attributes = $arg->getAttributes();
Expand Down
5 changes: 2 additions & 3 deletions src/Rules/Functions/ArrayValuesRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function processNode(Node $node, Scope $scope): array
$scope,
$node->getArgs(),
$functionReflection->getVariants(),
null,
$functionReflection->getNamedArgumentsVariants(),
);

$normalizedFuncCall = ArgumentsNormalizer::reorderFuncArguments($parametersAcceptor, $node);
Expand All @@ -66,8 +66,7 @@ public function processNode(Node $node, Scope $scope): array
}

$args = $normalizedFuncCall->getArgs();

if (count($args) !== 1) {
if (count($args) === 0) {
return [];
}

Expand Down
60 changes: 37 additions & 23 deletions tests/PHPStan/Analyser/ArgumentsNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,43 @@ public function dataReorderValid(): iterable
new StringType(),
],
];

yield [
[
['one', true, false, new IntegerType()],
['two', true, false, new StringType()],
['three', true, false, new FloatType()],
],
[],
[],
];

yield [
[
['one', true, false, new IntegerType()],
['two', true, false, new StringType()],
['three', true, false, new FloatType()],
],
[
[new StringType(), 'onee'],
],
[],
];

yield [
[
['one', true, false, new IntegerType()],
['two', true, false, new StringType()],
['three', true, false, new FloatType()],
],
[
[new IntegerType(), null],
[new StringType(), 'onee'],
],
[
new IntegerType(),
],
];
}

/**
Expand Down Expand Up @@ -282,29 +319,6 @@ public function dataReorderInvalid(): iterable
[new StringType(), 'three'],
],
];

yield [
[
['one', true, false, new IntegerType()],
['two', true, false, new StringType()],
['three', true, false, new FloatType()],
],
[
[new StringType(), 'onee'],
],
];

yield [
[
['one', true, false, new IntegerType()],
['two', true, false, new StringType()],
['three', true, false, new FloatType()],
],
[
[new IntegerType(), null],
[new StringType(), 'onee'],
],
];
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/PHPStan/Rules/Functions/data/array_values_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
array_values([null, 0]);
array_values([]);

array_values(array: $array);
array_values(array: $list);
array_values(unused: true, array: $array);
array_values(unused: true, array: $list);

0 comments on commit 17e5bac

Please sign in to comment.