Skip to content

[CodeQuality] Skip InlineConstructorDefaultToPropertyRector on non-final class - #8310

Open
TomasVotruba wants to merge 3 commits into
mainfrom
skip-inline-constructor-on-non-final
Open

[CodeQuality] Skip InlineConstructorDefaultToPropertyRector on non-final class#8310
TomasVotruba wants to merge 3 commits into
mainfrom
skip-inline-constructor-on-non-final

Conversation

@TomasVotruba

@TomasVotruba TomasVotruba commented Aug 6, 2026

Copy link
Copy Markdown
Member

Continues #8281 by @Junaid-PK (rebased on main, fixture restructured). Fixes rectorphp/rector#9837

InlineConstructorDefaultToPropertyRector moves initialization from runtime constructor flow to object creation. On a non-final class a child can omit parent::__construct() and still rely on the declared property default, so the move changes observable behavior.

Previously the rule fired on any class:

 class ValidatedBase
 {
-    private bool $validated = false;
+    private bool $validated = true;

     public function __construct()
     {
         $this->validate();
-        $this->validated = true;
     }
 }

 final class SkipsParentConstructor extends ValidatedBase
 {
     // never calls parent::__construct(), so $validated used to stay false
     public function __construct()
     {
     }
 }

Now non-final classes are left untouched; final classes are inlined as before.

The rule documentation and existing positive fixtures already use final classes, so this makes that boundary explicit.

Fixture follows the Source/ + namespaced Fixture/ convention: Source/ValidatedBase.php holds the parent, Fixture/skip_non_final_class.php.inc the non-final child that must stay unchanged.

@TomasVotruba
TomasVotruba force-pushed the skip-inline-constructor-on-non-final branch from fe69cca to adafe11 Compare August 6, 2026 20:06
@TomasVotruba
TomasVotruba enabled auto-merge (squash) August 6, 2026 21:15
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.

Incorrect behavior of InlineConstructorDefaultToPropertyRector

2 participants