EmptyOnNullableObjectToInstanceOfRector

Change empty() on nullable object to instanceof check

 class SomeClass
 {
     public function run(?AnotherObject $anotherObject)
     {
-        if (empty($anotherObject)) {
+        if (! $anotherObject instanceof AnotherObject) {
             return false;
         }

         return true;
     }
 }

Configure your rector.php:

<?php

use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\Empty_\EmptyOnNullableObjectToInstanceOfRector;

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