ReturnUnionTypeRector

Add union return type

 final class SomeClass
 {
-    public function getData()
+    public function getData(): null|\DateTime|\stdClass
     {
         if (rand(0, 1)) {
             return null;
         }

         if (rand(0, 1)) {
             return new DateTime('now');
         }

         return new stdClass;
     }
 }

Configure your rector.php:

<?php

use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnUnionTypeRector;

return RectorConfig::configure()
    ->withRules([
        ReturnUnionTypeRector::class,
    ]);