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

[Scoper] Add CommunityNodeVisitorAbstract to be used for community that include getRuleDefinition() empty method #6476

Closed
wants to merge 4 commits into from

Conversation

samsonasik
Copy link
Member

@TomasVotruba this is what I mean.

On rector-src code base, the AbstractRector still enforce to have getRuleDefinition() method, but not for community, but still have empty method for it.

This PR add CommunityNodeVisitorAbstract to be extended from AbstractRector on scoping process, to avoid issue like what @ruudk have at rectorphp/rector#8815 (comment)

@ruudk
Copy link
Contributor

ruudk commented Nov 23, 2024

Do I understand correctly that I can just remove the whole getRuleDefinition and be done with it? I don't really want / need that anyway...

@ruudk
Copy link
Contributor

ruudk commented Nov 23, 2024

Ah no, I just removed it and then it complains about it.

@samsonasik
Copy link
Member Author

@ruudk this is for safe belt, the replace to use CommunityNodeVisitorAbstract happen on scoper process, so it have empty getRuleDefinition() for community that extends AbstractRector.

see https://3v4l.org/OAS8Q

@ruudk
Copy link
Contributor

ruudk commented Nov 23, 2024

Got it, makes sense!

@samsonasik
Copy link
Member Author

All checks have passed 🎉 @TomasVotruba I think it is ready.

@TomasVotruba
Copy link
Member

@TomasVotruba
Copy link
Member

This PR is wrong, as it would only silence the removal. The method getDefinitin() should be removed instead 👍

@samsonasik samsonasik deleted the add-community-node-visitor-abstract branch November 23, 2024 08:10
@ruudk
Copy link
Contributor

ruudk commented Nov 23, 2024

If I remove getRuleDefinition I get an error too.

/Volumes/CS/www/cosmos/vendor/bin/rector process /Volumes/CS/www/cosmos/src-dev/Rector/StaticMoneyConstructorRector.php
PHP Fatal error: Class Dev\Rector\StaticMoneyConstructorRector contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface::getRuleDefinition) in /Volumes/CS/www/cosmos/src-dev/Rector/StaticMoneyConstructorRector.php on line 23
Fatal error: Class Dev\Rector\StaticMoneyConstructorRector contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface::getRuleDefinition) in /Volumes/CS/www/cosmos/src-dev/Rector/StaticMoneyConstructorRector.php on line 23

@samsonasik
Copy link
Member Author

@ruudk that seems due to overlapped with real dependency of symplify/rule-doc-generator, I guess remove #[\Override] is the way, since it exists on parent based on autoload, but not exists based on rector.

Could you create simple reproducible repo for that that show the error?

@ruudk
Copy link
Contributor

ruudk commented Nov 23, 2024

It's because I use symplify/coding-standard 12.2.3

How to deal with that now?

@samsonasik
Copy link
Member Author

@ruudk remove #[\Override] attribute on getRuleDefiniton() is the way

@ruudk
Copy link
Contributor

ruudk commented Nov 23, 2024

That is not a solution, as now PHPStan complains that I should add #[Override] because I have checkMissingOverrideMethodAttribute: true

Method Dev\Rector\StaticMoneyConstructorRector::getRuleDefinition() overrides method Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface::getRuleDefinition() but is missing the #[\Override] attribute.
🔖 method.missingOverride
↳ src-dev/Rector/StaticMoneyConstructorRector.php:25

@ruudk
Copy link
Contributor

ruudk commented Nov 23, 2024

So the problem is, that PHPStan sees different code than what Rector sees. So if I fix it for Rector, it breaks for PHPStan. And visa versa.

@samsonasik
Copy link
Member Author

I think register to phpstan ignoreErrors is the way for that

@ruudk
Copy link
Contributor

ruudk commented Nov 23, 2024

Sorry, but this is wrong. Ignoring that error in PHPStan is not a solution. Why does PHPStan see it that way?

@ruudk
Copy link
Contributor

ruudk commented Nov 23, 2024

Shouldn't we remove DocumentedRuleInterface from https://github.com/rectorphp/rector-src/blob/main/src/Contract/Rector/RectorInterface.php ?

@samsonasik
Copy link
Member Author

because PHPStan sees autoload from vendor/autoload.php, rector load RectorInterface that implements DocumentedRuleInterface from its prefixed vendor.

I will create new PR to remove DocumentedRuleInterface from RectorInterface on scoped prefixed vendor.

-interface RectorInterface extends NodeVisitor, DocumentedRuleInterface
+interface RectorInterface extends NodeVisitor

so it won't error.

@ruudk
Copy link
Contributor

ruudk commented Nov 23, 2024

That seems like it! 😁

@samsonasik
Copy link
Member Author

new PR:

@TomasVotruba
Copy link
Member

Thank you for pushing this one for a better solution than my first one 👏

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