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::$slideswith generic classDoctrine\Common\Collections\ArrayCollectiondoes not specify its types: TKey, T
💡 You can turn this off by settingcheckGenericClassInNonGenericObjectType: falsein 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: TKey and T. So ArrayCollection<Slide> isn't sufficient, you need something like ArrayCollection<int, Slide>.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With