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

[Renaming] New Rule: RenameFunctionLikeParamWithinCallLikeArgRector #5554

Conversation

peterfox
Copy link
Contributor

@peterfox peterfox commented Feb 4, 2024

Changes

  • Adds a new RenameFunctionLikeParamWithinCallLikeArgRector rule in the Renaming group
  • Adds a value object for configuring the rule
  • Adds a test with several scenarios
  • Updates the docs

Why

Similar to #5547 in that it can find a parameter to a FunctionLike structure supplied as an Arg to a MethodCall. Then it will rename the Param and apply that to any usage of the variable inside the FunctionLike.

-(new SomeClass)->process(function ($param) {});
+(new SomeClass)->process(function ($parameter) {});

with a example configuration of:

[new RenameFunctionLikeParamWithinCallLikeArg(
    'SomeClass', 
    'process', 
    0, // position of the Arg FunctionLike in the CallLike object, can also be a string of the args name.
    0, // position of the Param in the FunctionLike
    'parameter'
)]

Notes

The renaming of the variable will only go as far as possible. If a further FunctionLike structure exists using that variable then it will ignore the rename of the variable.

…n-call-like

# Conflicts:
#	build/target-repository/docs/rector_rules_overview.md
@peterfox peterfox requested a review from samsonasik February 18, 2024 14:05
@peterfox
Copy link
Contributor Author

Thank you @samsonasik!

@peterfox peterfox requested a review from samsonasik February 22, 2024 01:02
@peterfox
Copy link
Contributor Author

@samsonasik I did some refactoring to clean up the rule by using some of the built-in services for detecting variable renaming. I wondered if you could have another look.

Co-authored-by: Abdul Malik Ikhsan <[email protected]>
@TomasVotruba
Copy link
Member

Thank you 👍

@TomasVotruba TomasVotruba merged commit 4951acc into rectorphp:main Feb 22, 2024
39 checks passed
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