diff --git a/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/skip_used_as_assign_expr_by_ref.php.inc b/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/skip_used_as_assign_expr_by_ref.php.inc new file mode 100644 index 0000000000..2bc1736dfd --- /dev/null +++ b/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/skip_used_as_assign_expr_by_ref.php.inc @@ -0,0 +1,17 @@ +foo; + } +} diff --git a/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/used_as_assign_expr.php.inc b/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/used_as_assign_expr.php.inc new file mode 100644 index 0000000000..f736447e58 --- /dev/null +++ b/rules-tests/Php81/Rector/Property/ReadOnlyPropertyRector/Fixture/used_as_assign_expr.php.inc @@ -0,0 +1,33 @@ +foo; + } +} + +?> +----- +foo; + } +} + +?> diff --git a/src/NodeManipulator/AssignManipulator.php b/src/NodeManipulator/AssignManipulator.php index 4b6af9f037..a71313d59f 100644 --- a/src/NodeManipulator/AssignManipulator.php +++ b/src/NodeManipulator/AssignManipulator.php @@ -67,7 +67,11 @@ public function isLeftPartOfAssign(Node $node): bool return true; } - return $node->getAttribute(AttributeKey::IS_ASSIGNED_TO) === true; + if ($node->getAttribute(AttributeKey::IS_ASSIGN_REF_EXPR) === true) { + return true; + } + + return $node->getAttribute(AttributeKey::IS_ASSIGN_OP_VAR) === true; } /** diff --git a/src/NodeTypeResolver/Node/AttributeKey.php b/src/NodeTypeResolver/Node/AttributeKey.php index 4aeed346fe..3305711dcd 100644 --- a/src/NodeTypeResolver/Node/AttributeKey.php +++ b/src/NodeTypeResolver/Node/AttributeKey.php @@ -181,6 +181,16 @@ final class AttributeKey */ public const IS_BEING_ASSIGNED = 'is_being_assigned'; + /** + * @var string + */ + public const IS_ASSIGN_OP_VAR = 'is_assign_op_var'; + + /** + * @var string + */ + public const IS_ASSIGN_REF_EXPR = 'is_assign_ref_expr'; + /** * @var string */ diff --git a/src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/AssignedToNodeVisitor.php b/src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/AssignedToNodeVisitor.php index 119b30be0b..e0872f9b90 100644 --- a/src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/AssignedToNodeVisitor.php +++ b/src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/AssignedToNodeVisitor.php @@ -7,6 +7,7 @@ use PhpParser\Node; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\AssignOp; +use PhpParser\Node\Expr\AssignRef; use PhpParser\NodeVisitorAbstract; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\NodeTypeResolver\PHPStan\Scope\Contract\NodeVisitor\ScopeResolverNodeVisitorInterface; @@ -19,7 +20,12 @@ final class AssignedToNodeVisitor extends NodeVisitorAbstract implements ScopeRe public function enterNode(Node $node): ?Node { if ($node instanceof AssignOp) { - $node->var->setAttribute(AttributeKey::IS_ASSIGNED_TO, true); + $node->var->setAttribute(AttributeKey::IS_ASSIGN_OP_VAR, true); + return null; + } + + if ($node instanceof AssignRef) { + $node->expr->setAttribute(AttributeKey::IS_ASSIGN_REF_EXPR, true); return null; }