Find the best Rector rule to solve your problem. Searching through 1007 rules.
Found 3 rules:
Improve Doctrine property @var collections type 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 = [];
public function setTrainings($trainings)
{
$this->trainings = $trainings;
}
}
Add default key to Collection generic type if missing in @param or @return of class method
use Doctrine\Common\Collections\Collection;
final class ReturnSimpleCollection
{
/**
- * @return Collection<string>
+ * @return Collection<int, string>
*/
public function someMethod()
{
}
}
Add more precise generics type to method that returns Collection
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
final class SomeClass
{
+ /**
+ * @return Collection<int, SomeClass>
+ */
public function getItems(): Collection
{
$collection = new ArrayCollection();
$collection->add(new SomeClass());
return $collection;
}
}