From 0c06da93972a98fc1e3a40dd7609d79d884efb0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anderson=20M=C3=BCller?= Date: Mon, 29 Jul 2024 00:24:02 +0200 Subject: [PATCH] Support more assign cases in PropertyFetchAssignManipulator (#6192) --- .../Fixture/skip_assign_op.php.inc | 23 +++++++++++++++++++ .../PropertyFetchAssignManipulator.php | 3 ++- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/skip_assign_op.php.inc diff --git a/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/skip_assign_op.php.inc b/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/skip_assign_op.php.inc new file mode 100644 index 00000000000..7c2fe7f1859 --- /dev/null +++ b/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/skip_assign_op.php.inc @@ -0,0 +1,23 @@ +name = $name; + + if ($flag) { + $this->name .= 'changed'; + } + + $this->count = 0; + if ($flag) { + ++$this->count; + } + } +} diff --git a/src/NodeManipulator/PropertyFetchAssignManipulator.php b/src/NodeManipulator/PropertyFetchAssignManipulator.php index 2281edfb276..862fdd0342e 100644 --- a/src/NodeManipulator/PropertyFetchAssignManipulator.php +++ b/src/NodeManipulator/PropertyFetchAssignManipulator.php @@ -6,6 +6,7 @@ use PhpParser\Node; use PhpParser\Node\Expr\Assign; +use PhpParser\Node\Expr\AssignOp; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Function_; @@ -43,7 +44,7 @@ function (Node $node) use ($propertyName, &$count): ?int { return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN; } - if (! $node instanceof Assign) { + if (! $node instanceof Assign && ! $node instanceof AssignOp) { return null; }