Skip to content

Commit

Permalink
[CodeQuality] Handle array destructuring of unpack on ArrayMergeOfNon…
Browse files Browse the repository at this point in the history
…ArraysToSimpleArrayRector (#5682)

* add failing test when using array deconstruction for ArrayMergeOfNonArraysToSimpleArrayRector

* Test auto commit after update github actions (#5676)

* Test auto commit after update github actions

* [ci-review] Rector Rectify

---------

Co-authored-by: GitHub Action <actions@github.com>

* handle unpack

* handle unpack

* handle unpack

* handle unpack

---------

Co-authored-by: Kévin Grenier <kgrenier@campings.com>
Co-authored-by: GitHub Action <actions@github.com>
  • Loading branch information
3 people committed Mar 3, 2024
1 parent 2846b01 commit 1cd83be
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
@@ -0,0 +1,46 @@
<?php

namespace Rector\Tests\CodeQuality\Rector\FuncCall\ArrayMergeOfNonArraysToSimpleArrayRector\Fixture;

class DestructuringArrays
{
public function go()
{
$values = array_merge(
[
['foo' => 'bar'],
...$this->deconstructable(),
]
);

return $values;
}

private function deconstructable()
{
return ['rector'];
}
}

?>
-----
<?php

namespace Rector\Tests\CodeQuality\Rector\FuncCall\ArrayMergeOfNonArraysToSimpleArrayRector\Fixture;

class DestructuringArrays
{
public function go()
{
$values = [['foo' => 'bar'], ...$this->deconstructable()];

return $values;
}

private function deconstructable()
{
return ['rector'];
}
}

?>
Expand Up @@ -93,7 +93,9 @@ public function refactor(Node $node): ?Node
continue;
}

$array->items[] = new ArrayItem($nestedArrayItemItem->value, $nestedArrayItemItem->key);
$array->items[] = $nestedArrayItemItem->unpack
? $nestedArrayItemItem
: new ArrayItem($nestedArrayItemItem->value, $nestedArrayItemItem->key);
$isAssigned = true;
}
}
Expand Down

0 comments on commit 1cd83be

Please sign in to comment.