Change switch (true) of returning cases to match (true) expression
class SomeClass
{
public function run($value)
{
- switch (true) {
- case $value === 0:
- return 'no';
- case $value === 1:
- return 'yes';
- default:
- return 'maybe';
- }
+ return match (true) {
+ $value === 0 => 'no',
+ $value === 1 => 'yes',
+ default => 'maybe',
+ };
}
}
Configure your rector.php:
<?php
use Rector\CodeQuality\Rector\Switch_\SwitchTrueToMatchRector;
use Rector\Config\RectorConfig;
return RectorConfig::configure()
->withRules([
SwitchTrueToMatchRector::class,
]);