Skip to content

Conversation

ruudk
Copy link
Contributor

@ruudk ruudk commented Feb 22, 2021

I realized that I did not provide the test case in #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. And since that one does not implement an interface, it will allow refactoring. While it shouldn't.

That means that the implementation in #5622 is not correct (and naive).

I'm trying to think of a way how to do this.

/cc @samsonasik

@ruudk
Copy link
Contributor Author

ruudk commented Feb 22, 2021

I think the best thing to do would be to rollback #5622 as it does not what it should do.

@ruudk
Copy link
Contributor Author

ruudk commented Feb 22, 2021

I'll work on a PR to see if I can implement it. /cc @samsonasik

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 ruudk force-pushed the check-if-interface branch from 336a3fd to a861eed Compare February 22, 2021 13:10
@ruudk
Copy link
Contributor Author

ruudk commented Feb 22, 2021

Master is broken... partial fix here > #5623

@samsonasik What do you think of this approach?

@ruudk ruudk changed the title [RenameMethodRector] Add failing test Skip RenameMethodRector on interface wildcard used Feb 22, 2021
@samsonasik
Copy link
Member

I think new fixture is better instead of modifying existing fixture to keep existing behaviour.

@ruudk
Copy link
Contributor Author

ruudk commented Feb 22, 2021

Yeah, not sure. As the old one did not solve my use case + I reverted the PR.

@ruudk
Copy link
Contributor Author

ruudk commented Feb 22, 2021

Ran this on my project and now it finally works without issues 🎉

@ruudk
Copy link
Contributor Author

ruudk commented Feb 23, 2021

@TomasVotruba What do you think?

@TomasVotruba
Copy link
Member

I'm waiting for CI to be green, so I can review & merge.

Also, could you separate the fixture into new file? Now it's extending an existing one and it's harder to see what is going on.

@TomasVotruba
Copy link
Member

TomasVotruba commented Feb 27, 2021

First, thank you both for putting time into this.

In the hindsight I see it was a mistake to go with wildcards on class type resolution. Here the PHPStorm refactoring or custom Rector rule should be used instead.

Surpassed by #5693 (comment)

@ruudk ruudk deleted the check-if-interface branch February 27, 2021 10:12
TomasVotruba added a commit that referenced this pull request Feb 21, 2024
rectorphp/rector-src@99a79f8 [TypeDeclaration] Fix abs() returns on ReturnTypeFromStrictTypedCallRector (#5652)
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