Repository navigation
[symfony] Accept inherited contracts and method attributes in "NoListenerWithoutContractRule" - #334
Merged
Conversation
…enerWithoutContractRule" A listener that extends a class implementing a listener interface has a contract, even if the class node itself lists no "implements"; for example a Doctrine 1 record listener that extends Doctrine_Record_Listener. Symfony also registers a listener through #[AsEventListener] on a method, not only on the class. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
LGTM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
NoListenerWithoutContractRulereports 2 kinds of listener that do have a contract:1. A contract inherited from a parent class
The rule checks only the
implementsof the class node itself. A listener that extends a class which implements a listener interface is reported, although it has a contract. An example is a Doctrine 1 record listener:The rule now also accepts the interfaces from the class reflection, which include the inherited ones.
2.
#[AsEventListener]on a methodSymfony registers a listener through the attribute on the class or on a method:
The rule read only the class attributes. It now also reads the method attributes.
Each case has a fixture in
NoListenerWithoutContractRuleTest. Both were reported before the change. The full suite, ECS, PHPStan and Rector pass.