diff --git a/rules-tests/CodeQuality/Rector/Class_/InlineConstructorDefaultToPropertyRector/Fixture/skip_non_final_class.php.inc b/rules-tests/CodeQuality/Rector/Class_/InlineConstructorDefaultToPropertyRector/Fixture/skip_non_final_class.php.inc new file mode 100644 index 00000000000..9b1adad7b09 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/Class_/InlineConstructorDefaultToPropertyRector/Fixture/skip_non_final_class.php.inc @@ -0,0 +1,23 @@ +validate(); + $this->validated = true; + } + + private function validate(): void + { + } +} + +final class SkipsParentConstructor extends ValidatedBase +{ + public function __construct() + { + } +} diff --git a/rules/CodeQuality/Rector/Class_/InlineConstructorDefaultToPropertyRector.php b/rules/CodeQuality/Rector/Class_/InlineConstructorDefaultToPropertyRector.php index e952fb1806f..e5249908480 100644 --- a/rules/CodeQuality/Rector/Class_/InlineConstructorDefaultToPropertyRector.php +++ b/rules/CodeQuality/Rector/Class_/InlineConstructorDefaultToPropertyRector.php @@ -78,6 +78,11 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { + // A child class may bypass the constructor and depend on the declared property default + if (! $node->isFinal()) { + return null; + } + $hasChanged = false; $constructClassMethod = $node->getMethod(MethodName::CONSTRUCT);