File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
rules-tests/DowngradePhp80/Rector/FuncCall/DowngradeSubstrFalsyRector/Fixture
rules/DowngradePhp80/Rector/FuncCall Expand file tree Collapse file tree 2 files changed +26
-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 SkipAsArrayKey
6+ {
7+ public function run ()
8+ {
9+ $ data = [
10+ substr ('a ' , 2 ) => 'foo '
11+ ];
12+
13+ var_dump ($ data );
14+ }
15+ }
Original file line number Diff line number Diff line change 66
77use PhpParser \Node ;
88use PhpParser \Node \Arg ;
9+ use PhpParser \Node \ArrayItem ;
910use PhpParser \Node \Expr ;
1011use PhpParser \Node \Expr \AssignOp ;
1112use PhpParser \Node \Expr \BinaryOp \Concat ;
@@ -77,12 +78,13 @@ public function getNodeTypes(): array
7778 If_::class,
7879 While_::class,
7980 Do_::class,
81+ ArrayItem::class,
8082 FuncCall::class,
8183 ];
8284 }
8385
8486 /**
85- * @param Cast|Empty_|BooleanNot|Ternary|Identical|Concat|MethodCall|StaticCall|AssignOp|If_|While_|Do_|FuncCall $node
87+ * @param Cast|Empty_|BooleanNot|Ternary|Identical|Concat|MethodCall|StaticCall|AssignOp|If_|While_|Do_|ArrayItem| FuncCall $node
8688 */
8789 public function refactor (Node $ node ): ?Node
8890 {
@@ -122,6 +124,14 @@ public function refactor(Node $node): ?Node
122124 return null ;
123125 }
124126
127+ if ($ node instanceof ArrayItem) {
128+ if ($ node ->key instanceof Expr) {
129+ $ node ->key ->setAttribute (self ::IS_UNCASTABLE , true );
130+ }
131+
132+ return null ;
133+ }
134+
125135 if ($ node instanceof CallLike) {
126136 if ($ node ->isFirstClassCallable ()) {
127137 return null ;
You can’t perform that action at this time.
0 commit comments