Skip to content

Commit 7bdd172

Browse files
committed
Fix ArgumentsNormalizer - do not overwrite already passed args
1 parent fb79f37 commit 7bdd172

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

src/Analyser/ArgumentsNormalizer.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ public static function reorderArgs(ParametersAcceptor $parametersAcceptor, array
239239
// order named args into the position the signature expects them
240240
$attributes = $arg->getAttributes();
241241
$attributes[self::ORIGINAL_ARG_ATTRIBUTE] = $arg;
242+
if (array_key_exists($argumentPositions[$argName], $reorderedArgs)) {
243+
continue;
244+
}
242245
$reorderedArgs[$argumentPositions[$argName]] = new Arg(
243246
$arg->value,
244247
$arg->byRef,

tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,6 +1926,14 @@ public function testNamedArguments(): void
19261926
'Named argument bar for variadic parameter ...$args of method NamedArgumentsMethod\Foo::doIpsum() expects string, int given.',
19271927
95,
19281928
],
1929+
[
1930+
'Argument for parameter $i has already been passed.',
1931+
116,
1932+
],
1933+
[
1934+
'Call to an undefined method NamedArgumentsMethod\Bar::doBaz().',
1935+
115,
1936+
],
19291937
]);
19301938
}
19311939

tests/PHPStan/Rules/Methods/data/named-arguments.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,27 @@ public function doDolor(): void
9696
}
9797

9898
}
99+
100+
class Bar
101+
{
102+
103+
public function doFoo(
104+
int $i,
105+
int $j,
106+
int $k, ?int $l = null
107+
)
108+
{
109+
110+
}
111+
112+
public function doBar(): void
113+
{
114+
$this->doFoo(
115+
$this->doBaz(),
116+
i: 1,
117+
j: 2,
118+
k: 3
119+
);
120+
}
121+
122+
}

0 commit comments

Comments
 (0)