[CodeQuality] Skip CompleteDynamicPropertiesRector when a not autoloaded ancestor may declare the property - #8441
Merged
TomasVotruba merged 1 commit intoSep 2, 2026
Conversation
…ded ancestor may declare the property The rule only checked the direct parent for autoloadability. When a property is declared in a not autoloaded grandparent (or higher ancestor), reflection cannot see it, so the rule wrongly added a redeclaration. Walk the whole ancestor chain instead.
TomasVotruba
deleted the
fix-complete-dynamic-properties-not-autoloaded-grandparent
branch
September 2, 2026 20:28
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#9882
Problem
CompleteDynamicPropertiesRectoronly verified that the direct parent class is autoloadable. When the used property is declared in a not autoloaded grandparent (or any higher ancestor), reflection cannot traverse into it, sohasInstanceProperty()returnsfalseand the rule wrongly adds apublic $configFactory;redeclaration to the child.This is why the reporter could only reproduce it with the parent class in a separate, not-scanned file - once the ancestor is inlined, reflection sees the property and the rule correctly skips.
Fix
Walk the whole ancestor chain via reflection. If any ancestor declares a parent that is not in the reflection provider, skip the class - a not autoloaded ancestor may already declare the property. This also subsumes the previous direct-parent-only check.
Added
skip_property_from_not_autoloaded_grandparentfixture covering the child -> in-file middle -> not autoloaded grandparent chain.