Convert array access to Arr::get() method call, skips isset/empty checks, assignments, unset, and null coalesce with throw expressions
-$array['key'];
-$array['nested']['key'];
-$array['key'] ?? 'default';
-$array['nested']['key'] ?? 'default';
+\Illuminate\Support\Arr::get($array, 'key');
+\Illuminate\Support\Arr::get($array, 'nested.key');
+\Illuminate\Support\Arr::get($array, 'key', 'default');
+\Illuminate\Support\Arr::get($array, 'nested.key', 'default');
$array['key'] ?? throw new Exception('Required');
isset($array['key']);
empty($array['key']);
$array['key'] = 'value';
unset($array['key']);
Configure your rector.php:
<?php
use RectorLaravel\Rector\ArrayDimFetch\ArrayToArrGetRector;
use Rector\Config\RectorConfig;
return RectorConfig::configure()
->withRules([
ArrayToArrGetRector::class,
]);