DoctrineKeyValueStyleRule: support named parameters#774
DoctrineKeyValueStyleRule: support named parameters#774hemberger wants to merge 4 commits intostaabm:mainfrom
Conversation
Since we configure which arguments to check by their position, this can break if the arguments are specified at the call site with named parameters (PHP 8.0+), which allows arguments to be passed out of order. By mapping named parameter arguments to the actual index in the function interface, we can properly handle out of order calls.
|
The PHP Linter test is failing because it runs in PHP 7.4. Since The other test failures appear to be unrelated to this PR. I'm happy to make any changes you request. Thank you! |
|
|
||
| $tableExpr = $args[0]->value; | ||
| // Map function parameter names to parameter index | ||
| $params = $methodReflection->getVariants()[0]->getParameters(); |
There was a problem hiding this comment.
can we utilize PHPStan native ArgumentsNormalizer?
There was a problem hiding this comment.
usually PHPStan core would normalize arguments before passing them into rules.
I wonder why we need another normalization?
do we have similar problems in other rules?
There was a problem hiding this comment.
I rewrote this with ArgumentsNormalizer, and it works as expected. Thanks!
do we have similar problems in other rules?
I would expect that any Rule or RTE selecting arguments by index would have this same issue. It looks like many of them do, but I suspect that most people wouldn't be using named parameters with these kinds of functions (though they could in theory).
Apply suggestion from code review. Co-authored-by: Markus Staab <maggus.staab@googlemail.com>
Since we configure which arguments to check by their position, this can break if the arguments are specified at the call site with named parameters (PHP 8.0+), which allows arguments to be passed out of order.
By mapping named parameter arguments to the actual index in the function interface, we can properly handle out of order calls.