From ec291c4358636e29c026f2d42d575470cde25c76 Mon Sep 17 00:00:00 2001 From: Pinchon Karim Date: Thu, 28 Jul 2022 21:26:35 +0200 Subject: [PATCH] Fix/do not inline constructor default when readonly (#2720) * fix: inline constructor default readonly * test: inline constructor default readonly --- .../Fixture/do_not_change_readonly.php.inc | 13 +++++++++++++ .../InlineConstructorDefaultToPropertyRector.php | 4 ++++ 2 files changed, 17 insertions(+) create mode 100644 rules-tests/CodeQuality/Rector/Class_/InlineConstructorDefaultToPropertyRector/Fixture/do_not_change_readonly.php.inc 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();