Remove unused if check to non-empty array before foreach of the array
class SomeClass
{
public function run()
{
$values = [];
- if ($values !== []) {
- foreach ($values as $value) {
- echo $value;
- }
+ foreach ($values as $value) {
+ echo $value;
}
}
}
Configure your rector.php
:
<?php
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\If_\RemoveUnusedNonEmptyArrayBeforeForeachRector;
return RectorConfig::configure()
->withRules([
RemoveUnusedNonEmptyArrayBeforeForeachRector::class,
]);