Skip to content

[CodeQuality] Skip CompleteDynamicPropertiesRector when a not autoloaded ancestor may declare the property - #8441

Merged
TomasVotruba merged 1 commit into
mainfrom
fix-complete-dynamic-properties-not-autoloaded-grandparent
Sep 2, 2026
Merged

[CodeQuality] Skip CompleteDynamicPropertiesRector when a not autoloaded ancestor may declare the property#8441
TomasVotruba merged 1 commit into
mainfrom
fix-complete-dynamic-properties-not-autoloaded-grandparent

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Fixes rectorphp/rector#9882

Problem

CompleteDynamicPropertiesRector only 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, so hasInstanceProperty() returns false and the rule wrongly adds a public $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_grandparent fixture covering the child -> in-file middle -> not autoloaded grandparent chain.

…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
TomasVotruba merged commit b1aa7ce into main Sep 2, 2026
44 checks passed
@TomasVotruba
TomasVotruba deleted the fix-complete-dynamic-properties-not-autoloaded-grandparent branch September 2, 2026 20:28
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.

CompleteDynamicPropertiesRector adds unneeded properties defined by a trait used in a grandparent class.

1 participant