Skip to content

Commit 3e5621e

Browse files
committed
Named arguments - fix optional arguments and variadics
1 parent f2ecdac commit 3e5621e

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

src/Rules/FunctionCallParametersCheck.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PhpParser\Node\Expr;
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Php\PhpVersion;
8+
use PHPStan\Reflection\ParameterReflection;
89
use PHPStan\Reflection\ParametersAcceptor;
910
use PHPStan\Reflection\ResolvedFunctionVariant;
1011
use PHPStan\Type\ErrorType;
@@ -409,8 +410,11 @@ private function processArguments(
409410
$namedArgumentAlreadyOccurred = true;
410411

411412
$parametersCount = count($parameters);
413+
$requiredParametersByName = array_filter($unusedParametersByName, static function (ParameterReflection $parameter): bool {
414+
return !$parameter->isOptional();
415+
});
412416
if (
413-
count($unusedParametersByName) !== 0
417+
count($requiredParametersByName) !== 0
414418
|| !$parametersAcceptor->isVariadic()
415419
|| $parametersCount <= 0
416420
|| $isBuiltin

tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,4 +1903,17 @@ public function testBug3546(): void
19031903
$this->analyse([__DIR__ . '/data/bug-3546.php'], []);
19041904
}
19051905

1906+
public function testBug4800(): void
1907+
{
1908+
if (!self::$useStaticReflectionProvider) {
1909+
$this->markTestSkipped('Test requires static reflection.');
1910+
}
1911+
1912+
$this->checkThisOnly = false;
1913+
$this->checkNullables = true;
1914+
$this->checkUnionTypes = true;
1915+
$this->phpVersion = 80000;
1916+
$this->analyse([__DIR__ . '/data/bug-4800.php'], []);
1917+
}
1918+
19061919
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php // lint >= 8.0
2+
3+
namespace Bug4800;
4+
5+
class HelloWorld
6+
{
7+
/**
8+
* @param string|int ...$arguments
9+
*/
10+
public function a(string $bar = '', ...$arguments): string
11+
{
12+
return '';
13+
}
14+
15+
public function b(): void
16+
{
17+
$this->a(bar: 'baz', foo: 'bar', c: 3);
18+
$this->a(foo: 'bar', c: 3);
19+
}
20+
}

0 commit comments

Comments
 (0)