-
-
Notifications
You must be signed in to change notification settings - Fork 0
Tweak MethodsShouldBePublicOrPrivateRule to accept abstract protected methods
#19
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
Conversation
Kocal
commented
Dec 15, 2025
| Q | A |
|---|---|
| Bug fix? | yes |
| New feature? | no |
| Fixed tickets | Close #15 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes issue #15 by modifying the MethodsShouldBePublicOrPrivateRule to allow protected methods in Twig Components when they implement abstract methods defined in traits. This is a necessary exception because traits like ComponentWithFormTrait require components to implement abstract protected methods such as instantiateForm().
Key Changes
- The rule now distinguishes between protected methods implementing abstract trait methods (allowed) and other protected methods (violations)
- Added logic to detect and report protected concrete methods from traits that are not overridden in the component class
- Added comprehensive test coverage for both AsTwigComponent and AsLiveComponent attributes
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Rules/TwigComponent/MethodsShouldBePublicOrPrivateRule.php | Added ReflectionProvider injection, implemented logic to detect abstract trait methods, and added checks for concrete trait methods |
| tests/Rules/TwigComponent/MethodsShouldBePublicOrPrivateRule/MethodsShouldBePublicOrPrivateRuleTest.php | Added tests for both violation cases (concrete protected trait methods) and no-violation cases (abstract protected trait methods) |
| tests/Rules/TwigComponent/MethodsShouldBePublicOrPrivateRule/Fixture/TestTraitWithAbstractMethod.php | New test fixture defining a trait with an abstract protected method |
| tests/Rules/TwigComponent/MethodsShouldBePublicOrPrivateRule/Fixture/TestTraitWithConcreteMethod.php | New test fixture defining a trait with a concrete protected method |
| tests/Rules/TwigComponent/MethodsShouldBePublicOrPrivateRule/Fixture/ComponentWithProtectedMethodFromTrait.php | Test fixture for AsTwigComponent implementing abstract trait method (no violation) |
| tests/Rules/TwigComponent/MethodsShouldBePublicOrPrivateRule/Fixture/ComponentWithProtectedConcreteMethodFromTrait.php | Test fixture for AsTwigComponent with concrete protected trait method (violation) |
| tests/Rules/TwigComponent/MethodsShouldBePublicOrPrivateRule/Fixture/LiveComponentWithProtectedMethodFromTrait.php | Test fixture for AsLiveComponent implementing abstract trait method (no violation) |
| tests/Rules/TwigComponent/MethodsShouldBePublicOrPrivateRule/Fixture/LiveComponentWithProtectedConcreteMethodFromTrait.php | Test fixture for AsLiveComponent with concrete protected trait method (violation) |
| README.md | Added documentation explaining the exception for protected methods implementing abstract trait methods, with a practical example using ComponentWithFormTrait |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| $methodName = $traitMethod->getName(); | ||
|
|
||
| // Skip if method is abstract (already handled above) |
Copilot
AI
Dec 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment "already handled above" is slightly misleading. Abstract methods are not "handled" in the earlier loop - they are intentionally allowed and skipped. Consider rephrasing to something like "Skip if method is abstract (abstract methods are allowed to be protected)" to better reflect the actual behavior.
| // Skip if method is abstract (already handled above) | |
| // Skip if method is abstract (abstract methods are allowed to be protected) |
DamienHarper
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @Kocal
0c1f9ef to
933956e
Compare