Convert nested ternary expressions to match(true) statements
class SomeClass
{
public function getValue($input)
{
- return $input > 100 ? 'more than 100' : ($input > 5 ? 'more than 5' : 'less');
+ return match (true) {
+ $input > 100 => 'more than 100',
+ $input > 5 => 'more than 5',
+ default => 'less',
+ };
}
}
Configure your rector.php:
<?php
use Rector\CodingStyle\Rector\Assign\NestedTernaryToMatchRector;
use Rector\Config\RectorConfig;
return RectorConfig::configure()
->withRules([
NestedTernaryToMatchRector::class,
]);