Skip to content

Commit 17e5bac

Browse files
committed
ArgumentsNormalizer - skip unused arguments in non-variadic signatures, still return a normalized call
1 parent cfedc7b commit 17e5bac

File tree

4 files changed

+42
-29
lines changed

4 files changed

+42
-29
lines changed

src/Analyser/ArgumentsNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ private static function reorderArgs(ParametersAcceptor $parametersAcceptor, Call
209209
);
210210
} else {
211211
if (!$hasVariadic) {
212-
return null;
212+
continue;
213213
}
214214

215215
$attributes = $arg->getAttributes();

src/Rules/Functions/ArrayValuesRule.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function processNode(Node $node, Scope $scope): array
5656
$scope,
5757
$node->getArgs(),
5858
$functionReflection->getVariants(),
59-
null,
59+
$functionReflection->getNamedArgumentsVariants(),
6060
);
6161

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

6868
$args = $normalizedFuncCall->getArgs();
69-
70-
if (count($args) !== 1) {
69+
if (count($args) === 0) {
7170
return [];
7271
}
7372

tests/PHPStan/Analyser/ArgumentsNormalizerTest.php

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,43 @@ public function dataReorderValid(): iterable
202202
new StringType(),
203203
],
204204
];
205+
206+
yield [
207+
[
208+
['one', true, false, new IntegerType()],
209+
['two', true, false, new StringType()],
210+
['three', true, false, new FloatType()],
211+
],
212+
[],
213+
[],
214+
];
215+
216+
yield [
217+
[
218+
['one', true, false, new IntegerType()],
219+
['two', true, false, new StringType()],
220+
['three', true, false, new FloatType()],
221+
],
222+
[
223+
[new StringType(), 'onee'],
224+
],
225+
[],
226+
];
227+
228+
yield [
229+
[
230+
['one', true, false, new IntegerType()],
231+
['two', true, false, new StringType()],
232+
['three', true, false, new FloatType()],
233+
],
234+
[
235+
[new IntegerType(), null],
236+
[new StringType(), 'onee'],
237+
],
238+
[
239+
new IntegerType(),
240+
],
241+
];
205242
}
206243

207244
/**
@@ -282,29 +319,6 @@ public function dataReorderInvalid(): iterable
282319
[new StringType(), 'three'],
283320
],
284321
];
285-
286-
yield [
287-
[
288-
['one', true, false, new IntegerType()],
289-
['two', true, false, new StringType()],
290-
['three', true, false, new FloatType()],
291-
],
292-
[
293-
[new StringType(), 'onee'],
294-
],
295-
];
296-
297-
yield [
298-
[
299-
['one', true, false, new IntegerType()],
300-
['two', true, false, new StringType()],
301-
['three', true, false, new FloatType()],
302-
],
303-
[
304-
[new IntegerType(), null],
305-
[new StringType(), 'onee'],
306-
],
307-
];
308322
}
309323

310324
/**

tests/PHPStan/Rules/Functions/data/array_values_list.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@
2020
array_values([null, 0]);
2121
array_values([]);
2222

23-
array_values(array: $array);
24-
array_values(array: $list);
23+
array_values(unused: true, array: $array);
24+
array_values(unused: true, array: $list);

0 commit comments

Comments
 (0)