diff --git a/rules-tests/Php71/Rector/List_/ListToArrayDestructRector/Fixture/skip_already_array_destruct.php.inc b/rules-tests/Php71/Rector/List_/ListToArrayDestructRector/Fixture/skip_already_array_destruct.php.inc new file mode 100644 index 00000000000..1b5b0bddad6 --- /dev/null +++ b/rules-tests/Php71/Rector/List_/ListToArrayDestructRector/Fixture/skip_already_array_destruct.php.inc @@ -0,0 +1,14 @@ + $line, + 'file' => $file, + ] = $trace; + } +} diff --git a/rules/Php71/Rector/List_/ListToArrayDestructRector.php b/rules/Php71/Rector/List_/ListToArrayDestructRector.php index 25d082344c9..f4e546d9edc 100644 --- a/rules/Php71/Rector/List_/ListToArrayDestructRector.php +++ b/rules/Php71/Rector/List_/ListToArrayDestructRector.php @@ -9,6 +9,7 @@ use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\List_; use PhpParser\Node\Stmt\Foreach_; +use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Rector\AbstractRector; use Rector\ValueObject\PhpVersionFeature; use Rector\VersionBonding\Contract\MinPhpVersionInterface; @@ -71,6 +72,10 @@ public function refactor(Node $node): ?Node return null; } + if ($node->var->getAttribute(AttributeKey::KIND) === List_::KIND_ARRAY) { + return null; + } + $list = $node->var; $node->var = new Array_($list->items); @@ -81,6 +86,10 @@ public function refactor(Node $node): ?Node return null; } + if ($node->valueVar->getAttribute(AttributeKey::KIND) === List_::KIND_ARRAY) { + return null; + } + $list = $node->valueVar; $node->valueVar = new Array_($list->items);