Skip to content
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

feat: add AddNamedArgumentsRector #6678

Closed
wants to merge 1 commit into from

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

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.

3 participants