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

Clean MethodToMethodCallRector #2554

Merged
merged 22 commits into from
Jun 24, 2022

Conversation

SelrahcD
Copy link
Contributor

Hi all!

I was playing with Rector, trying to implement a new Rector and needed to make a replacement for a method from the current class. I managed to do it using AbstractRector::isObjectType and AbstractRector::isName and it felt simpler from what I saw in the MethodCallToMethodCallRector.

I decided to give it a try and see if I could clean the rule a little, and apparently, I managed to do it, as all tests are still passing. I removed some unnecessary checks and some of the logic that seems to not be mandatory.

Still, maybe I don't know something and the previous implementation might be better.

@SelrahcD SelrahcD requested a review from TomasVotruba as a code owner June 22, 2022 16:32
@samsonasik
Copy link
Member

Thank you for the contribution, since it can cause issue that never exist before, it should not be applied.

@samsonasik samsonasik closed this Jun 23, 2022
@TomasVotruba
Copy link
Member

TomasVotruba commented Jun 23, 2022

Hi, possibly test coverage needs to be improved :) if you can add tests cases from the feedback of @samsonasik , and types are strict and passing, we can move forward.

@samsonasik Let's leave it open to give space for feedback loop.

@TomasVotruba TomasVotruba reopened this Jun 23, 2022
@SelrahcD
Copy link
Contributor Author

Hi!

First, thanks for reopening the PR. I saw the closing message this morning and I was a bit surprised. No harm done and let's move

Adding the missing test cases and moving the method call outside the loop was my plan.

I'll probably need some clarification as I don't understand one of the comments :)

@SelrahcD
Copy link
Contributor Author

In the end, I'm a bit lost on what that rule should do. Should it replace all calls to a method call or just in some cases ?

What is the expected behavior if the dependency comes from a function call, like #2554 (comment)?
How should we handle a call to a method defined in parent or child classes?

On one end it seems that having a rule that does all replacements could be useful, and on the other, I get that doing so might be problematic in some codebases, mostly with the replacement of methods that were overridden in child classes.

@SelrahcD
Copy link
Contributor Author

I have added back the check for only replacing methods from the current class and not from parent and a few test cases.

In the end we probably all don't have the same understanding of what that rule should be doing. Maybe it would be better to just stick to the previous behavior of only modifying method calls to injected service, as @samsonasik understood it. The more behavior we add to the rule the more it will be difficult to decide what it should be doing or not.

Anyway, I've learned a few things, so thank you for your time and feedbacks :)

@SelrahcD
Copy link
Contributor Author

I made the requested changes :)

@samsonasik
Copy link
Member

Not really necessary on PR, but you can fix cs via command:

composer fix-cs -- rules/Transform/Rector/MethodCall/MethodCallToMethodCallRector.php

Copy link
Member

@TomasVotruba TomasVotruba left a comment

Choose a reason for hiding this comment

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

Thank you 👍

@TomasVotruba TomasVotruba merged commit 38b6b60 into rectorphp:main Jun 24, 2022
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