Simplify foreach
loops into in_array
when possible
-foreach ($items as $item) {
- if ($item === 'something') {
- return true;
- }
-}
-
-return false;
+return in_array('something', $items, true);
Configure your rector.php
:
<?php
use Rector\CodeQuality\Rector\Foreach_\ForeachToInArrayRector;
use Rector\Config\RectorConfig;
return RectorConfig::configure()
->withRules([
ForeachToInArrayRector::class,
]);