File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeSubstrFalsyRector/Fixture
rules/DowngradePhp80/Rector/FuncCall Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Tests \DowngradePhp80 \Rector \FuncCall \DowngradeSubstrFalsyRector \Fixture ;
4+
5+ class SkipAsArrayDimFetchDim
6+ {
7+ public function run ()
8+ {
9+ $ data [substr ('a ' , 2 )] = 'foo ' ;
10+ var_dump ($ data );
11+ }
12+ }
Original file line number Diff line number Diff line change 88use PhpParser \Node \Arg ;
99use PhpParser \Node \ArrayItem ;
1010use PhpParser \Node \Expr ;
11+ use PhpParser \Node \Expr \ArrayDimFetch ;
1112use PhpParser \Node \Expr \AssignOp ;
1213use PhpParser \Node \Expr \BinaryOp \Concat ;
1314use PhpParser \Node \Expr \BinaryOp \Identical ;
@@ -79,12 +80,13 @@ public function getNodeTypes(): array
7980 While_::class,
8081 Do_::class,
8182 ArrayItem::class,
83+ ArrayDimFetch::class,
8284 FuncCall::class,
8385 ];
8486 }
8587
8688 /**
87- * @param Cast|Empty_|BooleanNot|Ternary|Identical|Concat|MethodCall|StaticCall|AssignOp|If_|While_|Do_|ArrayItem|FuncCall $node
89+ * @param Cast|Empty_|BooleanNot|Ternary|Identical|Concat|MethodCall|StaticCall|AssignOp|If_|While_|Do_|ArrayItem|ArrayDimFetch| FuncCall $node
8890 */
8991 public function refactor (Node $ node ): ?Node
9092 {
@@ -132,6 +134,14 @@ public function refactor(Node $node): ?Node
132134 return null ;
133135 }
134136
137+ if ($ node instanceof ArrayDimFetch) {
138+ if ($ node ->dim instanceof Expr) {
139+ $ node ->dim ->setAttribute (self ::IS_UNCASTABLE , true );
140+ }
141+
142+ return null ;
143+ }
144+
135145 if ($ node instanceof CallLike) {
136146 if ($ node ->isFirstClassCallable ()) {
137147 return null ;
You can’t perform that action at this time.
0 commit comments