Skip to content

Commit 19aa1d7

Browse files
committed
skip nested arrays
1 parent d7dffdd commit 19aa1d7

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

rules-tests/CodeQuality/Rector/ClassMethod/InlineArrayReturnAssignRector/Fixture/nested_dim_fetch.php.inc renamed to rules-tests/CodeQuality/Rector/ClassMethod/InlineArrayReturnAssignRector/Fixture/skip_nested_dim_fetch.php.inc

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Rector\Tests\CodeQuality\Rector\ClassMethod\InlineArrayReturnAssignRector\Fixture;
44

5-
final class NestedDimFetch
5+
final class SkipNestedDimFetch
66
{
77
public static function getData(): array
88
{
@@ -17,19 +17,17 @@ final class NestedDimFetch
1717
return $data;
1818
}
1919
}
20-
21-
?>
2220
-----
2321
<?php
2422

2523
namespace Rector\Tests\CodeQuality\Rector\ClassMethod\InlineArrayReturnAssignRector\Fixture;
2624

27-
final class NestedDimFetch
25+
final class SkipNestedDimFetch
2826
{
29-
public function run()
27+
public static function getData(): array
3028
{
31-
return ['Timmy', 'Back'];
29+
return ['info' => [
30+
'one' => 123,
31+
]];
3232
}
3333
}
34-
35-
?>

rules/CodeQuality/NodeAnalyzer/VariableDimFetchAssignResolver.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ private function setNestedKeysExpr(array &$exprsByKeys, array $keys, Expr $expr)
8686
$keys = array_reverse($keys);
8787

8888
foreach ($keys as $key) {
89+
if ($reference instanceof Expr\Array_) {
90+
return;
91+
}
92+
8993
// create intermediate arrays automatically
9094
$reference = &$reference[$key];
9195
}

0 commit comments

Comments
 (0)