1818use PhpParser \NodeVisitor ;
1919use PHPStan \Type \ObjectType ;
2020use Rector \Contract \Rector \ConfigurableRectorInterface ;
21+ use Rector \NodeTypeResolver \Node \AttributeKey ;
2122use Rector \Rector \AbstractRector ;
2223use Rector \Transform \ValueObject \ArrayDimFetchToMethodCall ;
2324use Symplify \RuleDocGenerator \ValueObject \CodeSample \ConfiguredCodeSample ;
@@ -72,9 +73,13 @@ public function refactor(Node $node)
7273 if (!$ node ->var instanceof ArrayDimFetch) {
7374 return null ;
7475 }
75- return $ this ->getMethodCall ($ node ->var , 'set ' , $ node ->expr ) ?? NodeVisitor:: DONT_TRAVERSE_CHILDREN ;
76+ return $ this ->createExplicitMethodCall ($ node ->var , 'set ' , $ node ->expr );
7677 }
77- return $ this ->getMethodCall ($ node , 'get ' );
78+ // is part of assign, skip
79+ if ($ node ->getAttribute (AttributeKey::IS_BEING_ASSIGNED )) {
80+ return null ;
81+ }
82+ return $ this ->createExplicitMethodCall ($ node , 'get ' );
7883 }
7984 public function configure (array $ configuration ): void
8085 {
@@ -90,7 +95,7 @@ private function handleIsset(Isset_ $isset)
9095 $ exprs = [];
9196 foreach ($ isset ->vars as $ var ) {
9297 if ($ var instanceof ArrayDimFetch) {
93- $ methodCall = $ this ->getMethodCall ($ var , 'exists ' );
98+ $ methodCall = $ this ->createExplicitMethodCall ($ var , 'exists ' );
9499 if ($ methodCall instanceof MethodCall) {
95100 $ exprs [] = $ methodCall ;
96101 continue ;
@@ -116,7 +121,7 @@ private function handleUnset(Unset_ $unset)
116121 $ stmts = [];
117122 foreach ($ unset ->vars as $ var ) {
118123 if ($ var instanceof ArrayDimFetch) {
119- $ methodCall = $ this ->getMethodCall ($ var , 'unset ' );
124+ $ methodCall = $ this ->createExplicitMethodCall ($ var , 'unset ' );
120125 if ($ methodCall instanceof MethodCall) {
121126 $ stmts [] = new Expression ($ methodCall );
122127 continue ;
@@ -136,7 +141,7 @@ private function handleUnset(Unset_ $unset)
136141 /**
137142 * @param 'get'|'set'|'exists'|'unset' $action
138143 */
139- private function getMethodCall (ArrayDimFetch $ arrayDimFetch , string $ action , ?Expr $ expr = null ): ?MethodCall
144+ private function createExplicitMethodCall (ArrayDimFetch $ arrayDimFetch , string $ action , ?Expr $ expr = null ): ?MethodCall
140145 {
141146 if (!$ arrayDimFetch ->dim instanceof Node) {
142147 return null ;
0 commit comments