Skip to content

Conversation

@Kocal
Copy link
Owner

@Kocal Kocal commented Dec 15, 2025

Q A
Bug fix? yes
New feature? no
Fixed tickets Close #15

Copy link

Copilot AI left a 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)
Copy link

Copilot AI Dec 15, 2025

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.

Suggested change
// Skip if method is abstract (already handled above)
// Skip if method is abstract (abstract methods are allowed to be protected)

Copilot uses AI. Check for mistakes.
Copy link

@DamienHarper DamienHarper left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @Kocal

@Kocal Kocal force-pushed the MethodsShouldBePublicOrPrivateRule-protected branch from 0c1f9ef to 933956e Compare December 15, 2025 23:29
@Kocal Kocal merged commit d614f11 into main Dec 15, 2025
8 checks passed
@Kocal Kocal deleted the MethodsShouldBePublicOrPrivateRule-protected branch December 15, 2025 23:35
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.

Following MethodsShouldBePublicOrPrivateRule conflicts with protected methods coming from traits

3 participants