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

Do not rename methods from interface when using wildcard #5564

Closed
wants to merge 1 commit into from

Conversation

ruudk
Copy link
Contributor

@ruudk ruudk commented Feb 15, 2021

Failing test for #5554

cc @samsonasik

@@ -25,6 +25,11 @@
'old',
'new'
),
new MethodCallRename(
'Rector\Renaming\Tests\Rector\MethodCall\RenameMethodRector\Fixture\*WildcardSubscriber',
Copy link
Member

@TomasVotruba TomasVotruba Feb 15, 2021

Choose a reason for hiding this comment

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

Could you provide https://3v4l.org proof that this fnmatch() works with expected class?
That would narrow the scope for the issue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good one. I checked, and it does work: https://3v4l.org/4tCj4

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem is that getOldClass() still contains the wildcard and is then passed to ClassManipulator::hasParentMethodOrInterface.

Screenshot 2021-02-16 at 09 13 46@2x

Copy link
Member

Choose a reason for hiding this comment

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

What is needed to fix it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know.

@samsonasik added this:

$implementsInterface = $this->classManipulator->hasParentMethodOrInterface(
$methodCallRename->getOldClass(),
$methodCallRename->getOldMethod()
);
if ($implementsInterface) {
continue;
}

But that doesn't have support for fnmatch.

I think that we should not use $methodCallRename->getOldClass() as it can be a FQCN or wildcard matching.

Instead, we should check if the Class $node has interfaces that implement $methodCallRename->getOldMethod() method. If that's the case, it should not rename. But I tried this already and I couldn't get it to work.

@samsonasik
Copy link
Member

@ruudk I cherry-picked your commit at PR #5622

@ruudk ruudk deleted the add-wildcard-test branch February 19, 2021 09:36
ruudk added a commit to ruudk/rector that referenced this pull request Feb 22, 2021
I realized that I did not provide the test case in rectorphp#5564 correctly as I was running it in my project.

By changing the existing test it fails again.

Why? Because `interface WildcardSubscriber` matches the config.
ruudk added a commit to ruudk/rector that referenced this pull request Feb 22, 2021
I realized that I did not provide the test case in rectorphp#5564 correctly as I was running it in my project.

By changing the existing test it fails again.

Why? Because `OtherWildcardSubscriber` does match the wildcard `*WildcardSubscriber`. That one does not implement an interface.

Because `$this->classManipulator->hasParentMethodOrInterface` just tries to find the first matching class that matches the wildcard, it checks that one always.

That means that the implementation in rectorphp#5622 is not correct (and naive).
ruudk added a commit to ruudk/rector that referenced this pull request Feb 22, 2021
I realized that I did not provide the test case in rectorphp#5564 correctly as I was running it in my project.

By changing the existing test it fails again.

Why? Because `OtherWildcardSubscriber` does match the wildcard `*WildcardSubscriber`. That one does not implement an interface.

Because `$this->classManipulator->hasParentMethodOrInterface` just tries to find the first matching class that matches the wildcard, it checks that one always.

That means that the implementation in rectorphp#5622 is not correct (and naive).
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