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;
}
}
Configure your rector.php
:
<?php
use Rector\Config\RectorConfig;
use Rector\Doctrine\TypedCollections\Rector\ClassMethod\CollectionDocblockGenericTypeRector;
return RectorConfig::configure()
->withRules([
CollectionDocblockGenericTypeRector::class,
]);