Skip to content

DoctrineKeyValueStyleRule: support named parameters#774

Open
hemberger wants to merge 4 commits intostaabm:mainfrom
hemberger:named-parameters
Open

DoctrineKeyValueStyleRule: support named parameters#774
hemberger wants to merge 4 commits intostaabm:mainfrom
hemberger:named-parameters

Conversation

@hemberger
Copy link
Copy Markdown
Contributor

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.

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.
@hemberger
Copy link
Copy Markdown
Contributor Author

The PHP Linter test is failing because it runs in PHP 7.4. Since tests/rules/data/doctrine-key-value-style-named-parameters.php will only be able to be linted with PHP 8.0+, would it be okay to have parallel-lint exclude that file?

The other test failures appear to be unrelated to this PR.

I'm happy to make any changes you request. Thank you!

Comment thread src/Rules/DoctrineKeyValueStyleRule.php Outdated

$tableExpr = $args[0]->value;
// Map function parameter names to parameter index
$params = $methodReflection->getVariants()[0]->getParameters();
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we utilize PHPStan native ArgumentsNormalizer?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment thread tests/rules/data/doctrine-key-value-style-named-parameters.php Outdated
hemberger and others added 3 commits April 17, 2026 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants