Skip to content

Commit 8b2e3f0

Browse files
committed
Named arguments - another fix in logic
1 parent 3e5621e commit 8b2e3f0

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

src/Rules/FunctionCallParametersCheck.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use PhpParser\Node\Expr;
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Php\PhpVersion;
8-
use PHPStan\Reflection\ParameterReflection;
98
use PHPStan\Reflection\ParametersAcceptor;
109
use PHPStan\Reflection\ResolvedFunctionVariant;
1110
use PHPStan\Type\ErrorType;
@@ -410,12 +409,8 @@ private function processArguments(
410409
$namedArgumentAlreadyOccurred = true;
411410

412411
$parametersCount = count($parameters);
413-
$requiredParametersByName = array_filter($unusedParametersByName, static function (ParameterReflection $parameter): bool {
414-
return !$parameter->isOptional();
415-
});
416412
if (
417-
count($requiredParametersByName) !== 0
418-
|| !$parametersAcceptor->isVariadic()
413+
!$parametersAcceptor->isVariadic()
419414
|| $parametersCount <= 0
420415
|| $isBuiltin
421416
) {

tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,18 +1706,10 @@ public function testNamedArguments(): void
17061706
'Parameter ...$args of method NamedArgumentsMethod\Foo::doIpsum() expects string, int given.',
17071707
91,
17081708
],
1709-
[
1710-
'Unknown parameter $foo in call to method NamedArgumentsMethod\Foo::doIpsum().',
1711-
92,
1712-
],
17131709
[
17141710
'Missing parameter $b (int) in call to method NamedArgumentsMethod\Foo::doIpsum().',
17151711
92,
17161712
],
1717-
[
1718-
'Unknown parameter $foo in call to method NamedArgumentsMethod\Foo::doIpsum().',
1719-
93,
1720-
],
17211713
[
17221714
'Missing parameter $a (int) in call to method NamedArgumentsMethod\Foo::doIpsum().',
17231715
93,
@@ -1913,7 +1905,12 @@ public function testBug4800(): void
19131905
$this->checkNullables = true;
19141906
$this->checkUnionTypes = true;
19151907
$this->phpVersion = 80000;
1916-
$this->analyse([__DIR__ . '/data/bug-4800.php'], []);
1908+
$this->analyse([__DIR__ . '/data/bug-4800.php'], [
1909+
[
1910+
'Missing parameter $bar (string) in call to method Bug4800\HelloWorld2::a().',
1911+
36,
1912+
],
1913+
]);
19171914
}
19181915

19191916
}

tests/PHPStan/Rules/Methods/data/bug-4800.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,21 @@ public function b(): void
1818
$this->a(foo: 'bar', c: 3);
1919
}
2020
}
21+
22+
class HelloWorld2
23+
{
24+
/**
25+
* @param string|int ...$arguments
26+
*/
27+
public function a(string $bar, ...$arguments): string
28+
{
29+
return '';
30+
}
31+
32+
public function b(): void
33+
{
34+
$this->a(bar: 'baz', foo: 'bar', c: 3);
35+
$this->a(foo: 'baz', bar: 'bar', c: 3);
36+
$this->a(foo: 'bar', c: 3);
37+
}
38+
}

0 commit comments

Comments
 (0)