Replace ArrayCollection with Collection&Selectable on some entity typing (fix previous commit)

Updated entity properties to use Collection&Selectable for better type safety and interoperability. This change affects User, Household, Calendar, Person, AccompanyingPeriod, and EntityWorkflow classes.
This commit is contained in:
Julien Fastré 2024-08-28 12:04:43 +02:00
parent c16219dc6d
commit b0485dbcc8
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
6 changed files with 22 additions and 19 deletions

View File

@ -120,12 +120,12 @@ class Calendar implements TrackCreationInterface, TrackUpdateInterface, HasCente
private ?int $id = null; private ?int $id = null;
/** /**
* @var ArrayCollection<int, Invite> * @var \Doctrine\Common\Collections\Collection<int, \Chill\CalendarBundle\Entity\Invite>&Selectable
*/ */
#[Serializer\Groups(['read', 'docgen:read'])] #[Serializer\Groups(['read', 'docgen:read'])]
#[ORM\OneToMany(mappedBy: 'calendar', targetEntity: Invite::class, cascade: ['persist', 'remove', 'merge', 'detach'], orphanRemoval: true)] #[ORM\OneToMany(mappedBy: 'calendar', targetEntity: Invite::class, cascade: ['persist', 'remove', 'merge', 'detach'], orphanRemoval: true)]
#[ORM\JoinTable(name: 'chill_calendar.calendar_to_invites')] #[ORM\JoinTable(name: 'chill_calendar.calendar_to_invites')]
private ArrayCollection $invites; private Collection&Selectable $invites;
#[Serializer\Groups(['read', 'docgen:read'])] #[Serializer\Groups(['read', 'docgen:read'])]
#[Assert\NotNull(message: 'calendar.A location is required')] #[Assert\NotNull(message: 'calendar.A location is required')]

View File

@ -83,10 +83,10 @@ class User implements UserInterface, \Stringable, PasswordAuthenticatedUserInter
private ?Location $mainLocation = null; private ?Location $mainLocation = null;
/** /**
* @var ArrayCollection<int, UserScopeHistory> * @var \Doctrine\Common\Collections\Collection<int, \Chill\MainBundle\Entity\User\UserScopeHistory>&Selectable
*/ */
#[ORM\OneToMany(mappedBy: 'user', targetEntity: UserScopeHistory::class, cascade: ['persist', 'remove'], orphanRemoval: true)] #[ORM\OneToMany(mappedBy: 'user', targetEntity: UserScopeHistory::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
private ArrayCollection $scopeHistories; private Collection&Selectable $scopeHistories;
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, length: 255)] #[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, length: 255)]
private string $password = ''; private string $password = '';
@ -98,10 +98,10 @@ class User implements UserInterface, \Stringable, PasswordAuthenticatedUserInter
private ?string $salt = null; private ?string $salt = null;
/** /**
* @var ArrayCollection<int, UserJobHistory> * @var \Doctrine\Common\Collections\Collection<int, \Chill\MainBundle\Entity\User\UserJobHistory>&Selectable
*/ */
#[ORM\OneToMany(mappedBy: 'user', targetEntity: UserJobHistory::class, cascade: ['persist', 'remove'], orphanRemoval: true)] #[ORM\OneToMany(mappedBy: 'user', targetEntity: UserJobHistory::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
private ArrayCollection $jobHistories; private Collection&Selectable $jobHistories;
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, length: 80)] #[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, length: 80)]
private string $username = ''; private string $username = '';

View File

@ -21,7 +21,6 @@ use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Order; use Doctrine\Common\Collections\Order;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Exception;
use Symfony\Component\Serializer\Annotation as Serializer; use Symfony\Component\Serializer\Annotation as Serializer;
use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Constraints as Assert;
@ -278,7 +277,7 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface
} }
/** /**
* @throws Exception * @throws \Exception
*/ */
public function getStepsChained(): array public function getStepsChained(): array
{ {

View File

@ -135,10 +135,10 @@ class AccompanyingPeriod implements
private ?Location $administrativeLocation = null; private ?Location $administrativeLocation = null;
/** /**
* @var ArrayCollection<int, Calendar> * @var \Doctrine\Common\Collections\Collection<int, \Chill\CalendarBundle\Entity\Calendar>&Selectable
*/ */
#[ORM\OneToMany(mappedBy: 'accompanyingPeriod', targetEntity: Calendar::class)] #[ORM\OneToMany(mappedBy: 'accompanyingPeriod', targetEntity: Calendar::class)]
private ArrayCollection $calendars; private Collection&Selectable $calendars;
#[Groups(['read', 'write', 'docgen:read'])] #[Groups(['read', 'write', 'docgen:read'])]
#[Assert\NotBlank(groups: [AccompanyingPeriod::STEP_CLOSED])] #[Assert\NotBlank(groups: [AccompanyingPeriod::STEP_CLOSED])]
@ -153,7 +153,7 @@ class AccompanyingPeriod implements
private ?ClosingMotive $closingMotive = null; private ?ClosingMotive $closingMotive = null;
/** /**
* @var Collection<(int|string), Comment> * @var \Doctrine\Common\Collections\Collection<int, \Chill\PersonBundle\Entity\AccompanyingPeriod\Comment>
*/ */
#[Assert\NotBlank(groups: [AccompanyingPeriod::STEP_DRAFT])] #[Assert\NotBlank(groups: [AccompanyingPeriod::STEP_DRAFT])]
#[ORM\OneToMany(mappedBy: 'accompanyingPeriod', targetEntity: Comment::class, cascade: ['persist', 'remove'], orphanRemoval: true)] #[ORM\OneToMany(mappedBy: 'accompanyingPeriod', targetEntity: Comment::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
@ -246,7 +246,7 @@ class AccompanyingPeriod implements
private ?ThirdParty $requestorThirdParty = null; private ?ThirdParty $requestorThirdParty = null;
/** /**
* @var Collection<int, Resource> * @var Collection<int, AccompanyingPeriod\Resource>
*/ */
#[Groups(['read', 'docgen:read'])] #[Groups(['read', 'docgen:read'])]
#[ORM\OneToMany(targetEntity: AccompanyingPeriod\Resource::class, mappedBy: 'accompanyingPeriod', cascade: ['persist', 'remove'], orphanRemoval: true)] #[ORM\OneToMany(targetEntity: AccompanyingPeriod\Resource::class, mappedBy: 'accompanyingPeriod', cascade: ['persist', 'remove'], orphanRemoval: true)]
@ -427,7 +427,7 @@ class AccompanyingPeriod implements
return $this; return $this;
} }
public function addResource(Resource $resource): self public function addResource(AccompanyingPeriod\Resource $resource): self
{ {
$resource->setAccompanyingPeriod($this); $resource->setAccompanyingPeriod($this);
$this->resources[] = $resource; $this->resources[] = $resource;
@ -592,7 +592,7 @@ class AccompanyingPeriod implements
} }
/** /**
* @return ReadableCollection<(int|string), Comment> * @return ReadableCollection<int, Comment>
*/ */
#[Groups(['read'])] #[Groups(['read'])]
public function getComments(): ReadableCollection public function getComments(): ReadableCollection
@ -897,6 +897,9 @@ class AccompanyingPeriod implements
return $this->requestorThirdParty; return $this->requestorThirdParty;
} }
/**
* @return Collection<int, AccompanyingPeriod\Resource>
*/
public function getResources(): Collection public function getResources(): Collection
{ {
return $this->resources; return $this->resources;

View File

@ -48,12 +48,12 @@ class Household implements HasCentersInterface
private CommentEmbeddable $commentMembers; private CommentEmbeddable $commentMembers;
/** /**
* @var ArrayCollection<int, HouseholdComposition> * @var \Doctrine\Common\Collections\Collection<int, \Chill\PersonBundle\Entity\Household\HouseholdComposition>&Selectable
*/ */
#[Assert\Valid(groups: ['household_composition'], traverse: true)] #[Assert\Valid(groups: ['household_composition'], traverse: true)]
#[ORM\OneToMany(mappedBy: 'household', targetEntity: HouseholdComposition::class, cascade: ['persist'], orphanRemoval: true)] #[ORM\OneToMany(mappedBy: 'household', targetEntity: HouseholdComposition::class, cascade: ['persist'], orphanRemoval: true)]
#[ORM\OrderBy(['startDate' => Criteria::DESC])] #[ORM\OrderBy(['startDate' => Criteria::DESC])]
private ArrayCollection $compositions; private Collection&Selectable $compositions;
#[Serializer\Groups(['read', 'docgen:read'])] #[Serializer\Groups(['read', 'docgen:read'])]
#[ORM\Id] #[ORM\Id]

View File

@ -39,6 +39,7 @@ use DateTime;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria; use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Collections\Selectable;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use libphonenumber\PhoneNumber; use libphonenumber\PhoneNumber;
use Symfony\Component\Serializer\Annotation\DiscriminatorMap; use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
@ -153,10 +154,10 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
private ?PersonCenterCurrent $centerCurrent = null; private ?PersonCenterCurrent $centerCurrent = null;
/** /**
* @var ArrayCollection<int, PersonCenterHistory> * @var \Doctrine\Common\Collections\Collection<int, \Chill\PersonBundle\Entity\Person\PersonCenterHistory>&Selectable
*/ */
#[ORM\OneToMany(mappedBy: 'person', targetEntity: PersonCenterHistory::class, cascade: ['persist', 'remove'])] #[ORM\OneToMany(mappedBy: 'person', targetEntity: PersonCenterHistory::class, cascade: ['persist', 'remove'])]
private ArrayCollection $centerHistory; private Collection&Selectable $centerHistory;
/** /**
* Array where customfield's data are stored. * Array where customfield's data are stored.
@ -1440,7 +1441,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
return $this; return $this;
} }
public function setCenterHistory(Collection $centerHistory): Person public function setCenterHistory(Collection&Selectable $centerHistory): Person
{ {
$this->centerHistory = $centerHistory; $this->centerHistory = $centerHistory;