diff --git a/rules-tests/CodeQuality/Rector/Class_/InlineConstructorDefaultToPropertyRector/Fixture/do_not_change_readonly.php.inc b/rules-tests/CodeQuality/Rector/Class_/InlineConstructorDefaultToPropertyRector/Fixture/do_not_change_readonly.php.inc new file mode 100644 index 00000000000..4d7296a7f14 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/Class_/InlineConstructorDefaultToPropertyRector/Fixture/do_not_change_readonly.php.inc @@ -0,0 +1,13 @@ +name = 'John'; + } +} diff --git a/rules/CodeQuality/Rector/Class_/InlineConstructorDefaultToPropertyRector.php b/rules/CodeQuality/Rector/Class_/InlineConstructorDefaultToPropertyRector.php index 67b12d06630..6b76a991d95 100644 --- a/rules/CodeQuality/Rector/Class_/InlineConstructorDefaultToPropertyRector.php +++ b/rules/CodeQuality/Rector/Class_/InlineConstructorDefaultToPropertyRector.php @@ -83,6 +83,10 @@ public function refactor(Node $node): ?Node continue; } + if ($property->isReadonly()) { + continue; + } + $propertyProperty = $property->props[0]; $propertyProperty->default = $defaultPropertyExprAssign->getDefaultExpr();