File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
rules-tests/Php85/Rector/ArrayDimFetch/ArrayFirstLastRector/Fixture
rules/Php85/Rector/ArrayDimFetch Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Rector \Tests \Php85 \Rector \ArrayDimFetch \ArrayFirstLastRector \Fixture ;
6+
7+ final class SkipAsVarAssigned
8+ {
9+ public function run ()
10+ {
11+ $ myArray = [
12+ 'test ' => ['label ' => ['show ' => false ]]
13+ ];
14+
15+ $ myArray [array_key_last ($ myArray )]['label ' ]['show ' ] = true ;
16+ var_dump ($ myArray );
17+ }
18+ }
Original file line number Diff line number Diff line change 77use PhpParser \Node ;
88use PhpParser \Node \Expr \ArrayDimFetch ;
99use PhpParser \Node \Expr \FuncCall ;
10+ use Rector \PHPStan \ScopeFetcher ;
1011use Rector \Rector \AbstractRector ;
1112use Rector \ValueObject \PhpVersionFeature ;
1213use Rector \VersionBonding \Contract \MinPhpVersionInterface ;
@@ -82,6 +83,11 @@ public function refactor(Node $node): ?FuncCall
8283 return null ;
8384 }
8485
86+ $ scope = ScopeFetcher::fetch ($ node ->var );
87+ if ($ scope ->isInExpressionAssign ($ node )) {
88+ return null ;
89+ }
90+
8591 $ functionName = $ this ->isName ($ node ->dim , self ::ARRAY_KEY_FIRST )
8692 ? 'array_first '
8793 : 'array_last ' ;
You can’t perform that action at this time.
0 commit comments