-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
@no-named-arguments leads to static analysis errors for variadic arguments #6163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This sounds like a shortcoming of PHPStan to me. What do you think, @ondrejmirtes @staabm? |
PHPUnit could in theory make use of the array keys of a But in general, you could use the |
Not sure what PHPStan should do here. This is named arguments call: $input = ['a' => 'foo', 'b' => 'bar'];
$mock->with(...$input); // invalid So PHPStan marks it as such. If you think there should be some exceptions to what is marked as valid and invalid with |
My opinion is that if PHPUnit allows this use-case, there shouldn't be class-wide |
PHPUnit has That being said, the argument can be made to have an exception from this rule. However, I am not sure that the use-case mentioned here is actually supported. |
What do you mean? Why shouldn't it be OK to pass an associative array to a function that just decides to use its values? There is nothing bad in doing so. |
What does passing an associative array as an argument have to do with named arguments? |
in combination with the |
Summary
The
InvocationMocker
class is annotated with@no-named-arguments
- as this is on a class-level, it also affects thewith()
function, that only has a single variadic argument. This leads to static analysis issues.Current behavior
When using PHPStan in a project where
with()
is used with an array (not a list), this may lead to a static analysis error (although the keys are ignored anyways):How to reproduce
Expected behavior
Both cases are a valid usage, so I'd expect there would be no static analysis errors.
The text was updated successfully, but these errors were encountered: