TypeNullableEntityFromDocblockRector

Add full nullable type coverage for Doctrine entity based on docblocks. Useful stepping stone to add type coverage while keeping entities safe to read and write getter/setters

 use Doctrine\ORM\Mapping as ORM;

 /**
  * @ORM\Entity()
  */
 class SomeEntity
 {
     /**
-     * @var string
      * @ORM\Id
      * @ORM\Column(type="string")
      * @ORM\GeneratedValue
      */
-    private $name;
+    private ?string $name = null;

-
-    /**
-     * @return string
-     */
-    public function getName()
+    public function getName(): ?string
     {
         return $this->name;
     }

-    /**
-     * @param string $name
-     */
-    public function setName($name): void
+    public function setName(?string $name): void
     {
         $this->name = $name;
     }
 }

Configure your rector.php:

<?php

use Rector\Config\RectorConfig;
use Rector\Doctrine\CodeQuality\Rector\Class_\TypeNullableEntityFromDocblockRector;

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