Change multiple null compares to ?? queue
class SomeClass
{
public function run()
{
- if ($this->orderItem !== null) {
- return $this->orderItem;
- }
-
- if ($this->orderItemUnit !== null) {
- return $this->orderItemUnit;
- }
-
- return null;
+ return $this->orderItem ?? $this->orderItemUnit;
}
}
Configure your rector.php
:
<?php
use Rector\CodeQuality\Rector\If_\ConsecutiveNullCompareReturnsToNullCoalesceQueueRector;
use Rector\Config\RectorConfig;
return RectorConfig::configure()
->withRules([
ConsecutiveNullCompareReturnsToNullCoalesceQueueRector::class,
]);