Skip to content

Commit

Permalink
Support (more) empty array dim fetch during assignment
Browse files Browse the repository at this point in the history
Fixes #760
  • Loading branch information
bobthecow committed Apr 24, 2023
1 parent 5350ce0 commit 4f567c5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/CodeCleaner/EmptyArrayDimFetchPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public function enterNode(Node $node)
$this->theseOnesAreFine[] = $node->expr;
} elseif ($node instanceof Foreach_ && $node->valueVar instanceof ArrayDimFetch) {
$this->theseOnesAreFine[] = $node->valueVar;
} elseif ($node instanceof ArrayDimFetch && $node->var instanceof ArrayDimFetch) {
// $a[]['b'] = 'c'
if (\in_array($node, $this->theseOnesAreFine)) {
$this->theseOnesAreFine[] = $node->var;
}
}

if ($node instanceof ArrayDimFetch && $node->dim === null) {
Expand Down
1 change: 1 addition & 0 deletions test/CodeCleaner/EmptyArrayDimFetchPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function validStatements()
['$foo->{$bar}[] = 1'],
['foreach ($bar as $foo[]) {}'],
['$bar = &$foo[]'],
['$foo[]["bar"] = "baz"'],
];

return $data;
Expand Down

0 comments on commit 4f567c5

Please sign in to comment.