Skip to content

Fix class scope refresh skipping class attributes when class node is already in class - #9004

Merged
samsonasik merged 1 commit into
rectorphp:mainfrom
APX403:fix-class-attribute-scope-refresh
Nov 18, 2026
Merged

samsonasik merged 1 commit into
rectorphp:mainfrom
APX403:fix-class-attribute-scope-refresh

Conversation

@APX403

@APX403 APX403 commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

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"}), with Node "PhpParser\Node\Expr\ClassConstFetch" with is missing scope required for scope refresh. It happens when AnnotationToAttributeRector and StringClassNameToClassConstantRector both run, as they do with withAttributesSets(doctrine: true) and withPhpSets(). 2.7.0 converts the same entity.

AnnotationToAttributeRector adds the attribute to the Class_ node. Since #8725, a class that is already in class scope is refreshed by processing only its stmts, so the new attribute group gets no scope. StringClassNameToClassConstantRector then turns the string inside it into a ClassConstFetch, and refreshing that node throws. The refresh now also processes the class attribute groups with the class scope, as PHPStan does, through the existing AttributeGroup case of resolveStmts().

The test runs both rules on a DiscriminatorMap like the one in the issue and fails with that exception on main.

…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
samsonasik merged commit e496b67 into rectorphp:main Nov 18, 2026
51 checks passed
@samsonasik

Copy link
Copy Markdown
Member

Thank you @APX403

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

"System error: "Node "PhpParser\Node\Expr\ClassConstFetch" with is missing scope required for scope refresh"

2 participants