ImproveDoctrineCollectionDocTypeInEntityRector

Improve @var, @param and @return types for Doctrine collections to make them useful both for PHPStan and PHPStorm

 use Doctrine\Common\Collections\Collection;
 use Doctrine\ORM\Mapping as ORM;

 /**
  * @ORM\Entity
  */
 class SomeClass
 {
     /**
      * @ORM\OneToMany(targetEntity=Trainer::class, mappedBy="trainer")
-     * @var Collection|Trainer[]
+     * @var Collection<int, Trainer>
      */
     private $trainings = [];

+    /**
+     * @param Collection<int, Trainer> $trainings
+     */
     public function setTrainings($trainings)
     {
         $this->trainings = $trainings;
     }
 }

Configure your rector.php:

<?php

use Rector\Config\RectorConfig;
use Rector\Doctrine\CodeQuality\Rector\Property\ImproveDoctrineCollectionDocTypeInEntityRector;

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