DowngradeArraySpreadRector
Replace array spread with array_merge function
class SomeClass
{
public function run()
{
$parts = ['apple', 'pear'];
- $fruits = ['banana', 'orange', ...$parts, 'watermelon'];
+ $fruits = array_merge(['banana', 'orange'], $parts, ['watermelon']);
}
public function runWithIterable()
{
- $fruits = ['banana', 'orange', ...new ArrayIterator(['durian', 'kiwi']), 'watermelon'];
+ $fruits = array_merge(
+ ['banana', 'orange'],
+ is_array(new ArrayIterator(['durian', 'kiwi'])) ?
+ new ArrayIterator(['durian', 'kiwi']) :
+ iterator_to_array(new ArrayIterator(['durian', 'kiwi'])),
+ ['watermelon']
+ );
}
}
Configure your rector.php:
<?php
use Rector\Config\RectorConfig;
use Rector\DowngradePhp74\Rector\Array_\DowngradeArraySpreadRector;
return RectorConfig::configure()
->withRules([
DowngradeArraySpreadRector::class,
]);