Skip to content

feat: add AddNamedArgumentsRector#6678

Closed
savinmikhail wants to merge 1 commit intorectorphp:mainfrom
savinmikhail:main
Closed

feat: add AddNamedArgumentsRector#6678
savinmikhail wants to merge 1 commit intorectorphp:mainfrom
savinmikhail:main

Conversation

@savinmikhail
Copy link

In two words this feature doing this:

- (new DateTimeImmutable())->format('Y-m-d');
+ (new DateTimeImmutable())->format(format: 'Y-m-d');

Also for functions, static methods, constructors

It seems for me and my teammates that code with named arguments less prone to errors and more readable

use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use const PHP_VERSION_ID;

final class AddNamedArgumentsRector extends AbstractRector
Copy link
Member

Choose a reason for hiding this comment

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

make implements Rector\VersionBonding\Contract\MinPhpVersionInterface instead of manual check on refactor.

Comment on lines +46 to +47
$parameters = $this->getParameters($node);
$this->addNamesToArgs($node, $parameters);
Copy link
Member

Choose a reason for hiding this comment

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

add hasChanged flag so can return null on no change

@TomasVotruba
Copy link
Member

Hi, thanks for the proposal.
While named arguments bring some value in multi-arg calls, it could backfire in using them everywhere.

Maintenance cost with renamed ctor args, renamed classes and then params could go to huge extreme.

Saying that, create this as a custom rule for your project, that fits your team needs 😇

@savinmikhail
Copy link
Author

Thank you guys for incredibly fast feedback :)

@savinmikhail
Copy link
Author

For anyone searching it, I made a standalone repo

@github-actions
Copy link
Contributor

This pull request has been automatically locked because it has been closed for 150 days. Please open a new PR if you want to continue the work.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants