1111use PhpParser \Node \Expr \Assign ;
1212use PhpParser \Node \Expr \AssignOp ;
1313use PhpParser \Node \Expr \AssignRef ;
14+ use PhpParser \Node \Expr \BinaryOp \Identical ;
15+ use PhpParser \Node \Expr \BinaryOp \NotIdentical ;
1416use PhpParser \Node \Expr \List_ ;
17+ use PhpParser \Node \Expr \Variable ;
1518use PhpParser \NodeVisitorAbstract ;
1619use Rector \Contract \PhpParser \DecoratingNodeVisitorInterface ;
1720use Rector \NodeTypeResolver \Node \AttributeKey ;
@@ -48,6 +51,11 @@ public function enterNode(Node $node): ?Node
4851
4952 $ node ->expr ->setAttribute (AttributeKey::IS_ASSIGNED_TO , true );
5053
54+ if ($ node ->expr instanceof Identical || $ node ->expr instanceof NotIdentical) {
55+ $ this ->markAssignVarInComparison ($ node ->var , $ node ->expr ->left );
56+ $ this ->markAssignVarInComparison ($ node ->var , $ node ->expr ->right );
57+ }
58+
5159 if ($ node ->expr instanceof Assign) {
5260 $ node ->var ->setAttribute (AttributeKey::IS_MULTI_ASSIGN , true );
5361 $ node ->expr ->setAttribute (AttributeKey::IS_MULTI_ASSIGN , true );
@@ -71,4 +79,17 @@ private function markAssignOpVar(Expr $expr): void
7179 $ expr ->setAttribute (AttributeKey::IS_ASSIGN_OP_VAR , true );
7280 }
7381 }
82+
83+ private function markAssignVarInComparison (Expr $ assignVar , Expr $ comparedExpr ): void
84+ {
85+ if (! $ assignVar instanceof Variable || ! $ comparedExpr instanceof Variable) {
86+ return ;
87+ }
88+
89+ if (! is_string ($ assignVar ->name ) || $ assignVar ->name !== $ comparedExpr ->name ) {
90+ return ;
91+ }
92+
93+ $ comparedExpr ->setAttribute (AttributeKey::IS_ASSIGN_VAR_IN_COMPARISON , true );
94+ }
7495}
0 commit comments