I'm running PHPStan on a Symfony project where I have the following relation in a Doctrine entity:
/**
* @ORM\OneToMany(targetEntity="App\Entity\Course\Slide", mappedBy="chapter", cascade={"persist"}, orphanRemoval=true)
* @ORM\OrderBy({"listOrder" = "ASC"})
*
* @var ArrayCollection<Slide>
*/
private $slides;
Running analysis with rule level 6 I got the following message about the property (and its getter return type):
Property
App\Entity\Course\Chapter::$slides
with generic classDoctrine\Common\Collections\ArrayCollection
does not specify its types: TKey, T
💡 You can turn this off by settingcheckGenericClassInNonGenericObjectType: false
in yourphpstan.neon
.
My edit attempts only confused PHPStan, maybe because I'm not fully understanding generics here. But silencing the message just because I don't get it would be stupid.
What am I supposed to add or change in the PHPDoc ?
ArrayCollection
has two type variables:
So ArrayCollection<Slide>
isn't sufficient, you need something like ArrayCollection<int, Slide>
.