-
Notifications
You must be signed in to change notification settings - Fork 54
Add rule to detect redundant trait usage #279
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
Add rule to detect redundant trait usage #279
Conversation
Hi,
I don't think this is a very common and bug-inducing problem. Additionally, there might be valid reasons to do this if you account for trait adaptations (with insteadof and as keywords).
As usual, feel free to publish this as your own package, or try to pitch this idea to other maintainers of strict rules packages like https://github.com/shipmonk-rnd/phpstan-rules or https://github.com/ergebnis/phpstan-rules 😊
@ondrejmirtes It's problematic performance-wise. On a client project, phpstan needed 7 minutes to complete. After eliminating excessive redundant trait use, we were down to ~3 minutes. It can be a huge performance penalty for phpstan, and the reason is obvious, the trait is evaluated in every possible context where it appears. This redundant trait usage is problematic for this reason. Also it indicates bad design, but it's opinionated.
Please report this in phpstan/phpstan as a performance bug with a reproducer.
This rule detects when a class uses both a trait A and trait B, where trait A already uses trait B (either directly or transitively).
Features
strictRules.noRedundantTraitUseparameterExample