Merge pull request #2872 from rectorphp/array-spread

Skip unpackaged args in ArraySpreadInsteadOfArrayMergeRector
This commit is contained in:
Tomas Votruba 2020-02-17 15:22:58 +01:00 committed by GitHub
commit efe1de4fe7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -100,8 +100,12 @@ PHP
$array = new Array_();
foreach ($funcCall->args as $arg) {
$value = $arg->value;
// cannot handle unpacked arguments
if ($arg->unpack) {
return null;
}
$value = $arg->value;
if ($this->shouldSkipArrayForInvalidTypeOrKeys($value)) {
return null;
}

View File

@ -0,0 +1,20 @@
<?php
namespace Rector\Php74\Tests\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\Fixture;
use stdClass;
class SkipSpreadyArrayMerge
{
public function run()
{
$values = [
[new stdClass()],
[new stdClass]
];
$items = array_merge(...$values);
return array_merge($items, ...$values);
}
}