Repository navigation
Fix class scope refresh skipping class attributes when class node is already in class - #9004
Merged
samsonasik merged 1 commit intoNov 18, 2026
Conversation
…already in class A changed class that is already in class scope only had its stmts processed, so an attribute group added to it, for example by AnnotationToAttributeRector, kept no scope, and refreshing a node that a later rule changed inside it threw "missing scope required for scope refresh". Process the class attribute groups with the class scope too. Fixes rectorphp/rector#9948
samsonasik
approved these changes
Nov 18, 2026
Member
|
Thank you @APX403 |
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.
Fixes rectorphp/rector#9948
Since 2.8.0, Rector skips a Doctrine entity whose class annotation holds a class name string, such as
@ORM\DiscriminatorMap({"page" = "App\Entity\Statistic\Page"}), withNode "PhpParser\Node\Expr\ClassConstFetch" with is missing scope required for scope refresh. It happens whenAnnotationToAttributeRectorandStringClassNameToClassConstantRectorboth run, as they do withwithAttributesSets(doctrine: true)andwithPhpSets(). 2.7.0 converts the same entity.AnnotationToAttributeRectoradds the attribute to theClass_node. Since #8725, a class that is already in class scope is refreshed by processing only itsstmts, so the new attribute group gets no scope.StringClassNameToClassConstantRectorthen turns the string inside it into aClassConstFetch, and refreshing that node throws. The refresh now also processes the class attribute groups with the class scope, as PHPStan does, through the existingAttributeGroupcase ofresolveStmts().The test runs both rules on a
DiscriminatorMaplike the one in the issue and fails with that exception on main.