Skip to content

Commit

Permalink
Named arguments - another fix in logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Apr 4, 2021
1 parent 3e5621e commit 8b2e3f0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
7 changes: 1 addition & 6 deletions src/Rules/FunctionCallParametersCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use PhpParser\Node\Expr;
use PHPStan\Analyser\Scope;
use PHPStan\Php\PhpVersion;
use PHPStan\Reflection\ParameterReflection;
use PHPStan\Reflection\ParametersAcceptor;
use PHPStan\Reflection\ResolvedFunctionVariant;
use PHPStan\Type\ErrorType;
Expand Down Expand Up @@ -410,12 +409,8 @@ private function processArguments(
$namedArgumentAlreadyOccurred = true;

$parametersCount = count($parameters);
$requiredParametersByName = array_filter($unusedParametersByName, static function (ParameterReflection $parameter): bool {
return !$parameter->isOptional();
});
if (
count($requiredParametersByName) !== 0
|| !$parametersAcceptor->isVariadic()
!$parametersAcceptor->isVariadic()
|| $parametersCount <= 0
|| $isBuiltin
) {
Expand Down
15 changes: 6 additions & 9 deletions tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1706,18 +1706,10 @@ public function testNamedArguments(): void
'Parameter ...$args of method NamedArgumentsMethod\Foo::doIpsum() expects string, int given.',
91,
],
[
'Unknown parameter $foo in call to method NamedArgumentsMethod\Foo::doIpsum().',
92,
],
[
'Missing parameter $b (int) in call to method NamedArgumentsMethod\Foo::doIpsum().',
92,
],
[
'Unknown parameter $foo in call to method NamedArgumentsMethod\Foo::doIpsum().',
93,
],
[
'Missing parameter $a (int) in call to method NamedArgumentsMethod\Foo::doIpsum().',
93,
Expand Down Expand Up @@ -1913,7 +1905,12 @@ public function testBug4800(): void
$this->checkNullables = true;
$this->checkUnionTypes = true;
$this->phpVersion = 80000;
$this->analyse([__DIR__ . '/data/bug-4800.php'], []);
$this->analyse([__DIR__ . '/data/bug-4800.php'], [
[
'Missing parameter $bar (string) in call to method Bug4800\HelloWorld2::a().',
36,
],
]);
}

}
18 changes: 18 additions & 0 deletions tests/PHPStan/Rules/Methods/data/bug-4800.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,21 @@ public function b(): void
$this->a(foo: 'bar', c: 3);
}
}

class HelloWorld2
{
/**
* @param string|int ...$arguments
*/
public function a(string $bar, ...$arguments): string
{
return '';
}

public function b(): void
{
$this->a(bar: 'baz', foo: 'bar', c: 3);
$this->a(foo: 'baz', bar: 'bar', c: 3);
$this->a(foo: 'bar', c: 3);
}
}

0 comments on commit 8b2e3f0

Please sign in to comment.