ChangeIfElseValueAssignToEarlyReturnRector

Change if/else value to early return

 class SomeClass
 {
     public function run()
     {
         if ($this->hasDocBlock($tokens, $index)) {
-            $docToken = $tokens[$this->getDocBlockIndex($tokens, $index)];
-        } else {
-            $docToken = null;
+            return $tokens[$this->getDocBlockIndex($tokens, $index)];
         }
-
-        return $docToken;
+        return null;
     }
 }

Configure your rector.php:

<?php

use Rector\Config\RectorConfig;
use Rector\EarlyReturn\Rector\If_\ChangeIfElseValueAssignToEarlyReturnRector;

return RectorConfig::configure()
    ->withRules([
        ChangeIfElseValueAssignToEarlyReturnRector::class,
    ]);
SETS:  Early return