From 59e9222be2f0b793c3cdb65e4efcdc533149ecf7 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 30 Nov 2021 23:34:28 +0700 Subject: [PATCH] [Php81] Skip has default value on ReadOnlyPropertyRector (#1355) --- .../Fixture/skip_has_default_value.php.inc | 18 ++++++++++++++++++ .../Rector/Property/ReadOnlyPropertyRector.php | 3 ++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/skip_has_default_value.php.inc diff --git a/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/skip_has_default_value.php.inc b/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/skip_has_default_value.php.inc new file mode 100644 index 00000000000..bde1eb011af --- /dev/null +++ b/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/skip_has_default_value.php.inc @@ -0,0 +1,18 @@ +name = $name; + } + + public function getName() + { + return $this->name; + } +} diff --git a/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php b/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php index db8318b5751..cc496943dc1 100644 --- a/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php +++ b/rules/Php81/Rector/Property/ReadOnlyPropertyRector.php @@ -5,6 +5,7 @@ namespace Rector\Php81\Rector\Property; use PhpParser\Node; +use PhpParser\Node\Expr; use PhpParser\Node\Param; use PhpParser\Node\Stmt\Property; use Rector\Core\NodeManipulator\PropertyManipulator; @@ -88,7 +89,7 @@ public function refactor(Node $node): ?Node return null; } - if ($node->isReadonly()) { + if ($node->isReadonly() || $node->props[0]->default instanceof Expr) { return null; }