DX: type-hing oneToMany and ManyToMany properties as collection

This commit is contained in:
2023-07-19 16:21:17 +02:00
parent 224c2c74e8
commit 075aca493b
32 changed files with 130 additions and 73 deletions

View File

@@ -23,6 +23,7 @@ use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Collections\ReadableCollection;
use Doctrine\Common\Collections\Selectable;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation as Serializer;
use Symfony\Component\Validator\Constraints as Assert;
@@ -45,6 +46,7 @@ class Household
/**
* Addresses.
*
* @var Collection<Address>
* @ORM\ManyToMany(
* targetEntity="Chill\MainBundle\Entity\Address",
* cascade={"persist", "remove", "merge", "detach"})
@@ -60,6 +62,7 @@ class Household
private CommentEmbeddable $commentMembers;
/**
* @var Collection&Selectable<int, HouseholdComposition>
* @ORM\OneToMany(
* targetEntity=HouseholdComposition::class,
* mappedBy="household",
@@ -69,7 +72,7 @@ class Household
* @ORM\OrderBy({"startDate": "DESC"})
* @Assert\Valid(traverse=true, groups={"household_composition"})
*/
private Collection $compositions;
private Collection&Selectable $compositions;
/**
* @ORM\Id
@@ -80,6 +83,7 @@ class Household
private ?int $id = null;
/**
* @var Collection<HouseholdMember>
* @ORM\OneToMany(
* targetEntity=HouseholdMember::class,
* mappedBy="household"
@@ -146,9 +150,9 @@ class Household
*
* @Assert\Callback(methods={"validate"})
*
* @return \Chill\MainBundle\Entity\Address[]
* @return Collection<Address>
*/
public function getAddresses()
public function getAddresses(): Collection
{
return $this->addresses;
}