Replace foreach with boolean assignment and break with array_any
-$found = false;
-foreach ($animals as $animal) {
- if (str_starts_with($animal, 'c')) {
- $found = true;
- break;
- }
-}
+$found = array_any($animals, fn($animal) => str_starts_with($animal, 'c'));
Configure your rector.php
:
<?php
use Rector\Config\RectorConfig;
use Rector\Php84\Rector\Foreach_\ForeachToArrayAnyRector;
return RectorConfig::configure()
->withRules([
ForeachToArrayAnyRector::class,
]);