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

@@ -11,6 +11,7 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Entity;
use Chill\CalendarBundle\Entity\Calendar;
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
use Chill\MainBundle\Entity\Address;
@@ -43,6 +44,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 Iterator;
use LogicException;
@@ -150,13 +152,12 @@ class AccompanyingPeriod implements
private ?Location $administrativeLocation = null;
/**
* @var Collection&Selectable<int, Calendar>
* @ORM\OneToMany(targetEntity="Chill\CalendarBundle\Entity\Calendar", mappedBy="accompanyingPeriod")
*/
private Collection $calendars;
private Collection&Selectable $calendars;
/**
* @var DateTime
*
* @ORM\Column(type="date", nullable=true)
* @Groups({"read", "write", "docgen:read"})
* @Assert\NotBlank(groups={AccompanyingPeriod::STEP_CLOSED})
@@ -242,6 +243,7 @@ class AccompanyingPeriod implements
private ?UserJob $job = null;
/**
* @var Collection<AccompanyingPeriodLocationHistory>
* @ORM\OneToMany(targetEntity=AccompanyingPeriodLocationHistory::class,
* mappedBy="period", cascade={"persist", "remove"}, orphanRemoval=true)
*/
@@ -320,6 +322,7 @@ class AccompanyingPeriod implements
private ?ThirdParty $requestorThirdParty = null;
/**
* @var Collection<Resource>
* @ORM\OneToMany(
* targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod\Resource",
* mappedBy="accompanyingPeriod",
@@ -332,6 +335,7 @@ class AccompanyingPeriod implements
private Collection $resources;
/**
* @var Collection<Scope>
* @ORM\ManyToMany(
* targetEntity=Scope::class,
* cascade={}
@@ -347,6 +351,7 @@ class AccompanyingPeriod implements
private Collection $scopes;
/**
* @var Collection<SocialIssue>
* @ORM\ManyToMany(
* targetEntity=SocialIssue::class
* )
@@ -366,6 +371,7 @@ class AccompanyingPeriod implements
private string $step = self::STEP_DRAFT;
/**
* @var Collection<AccompanyingPeriodStepHistory>
* @ORM\OneToMany(targetEntity=AccompanyingPeriodStepHistory::class,
* mappedBy="period", cascade={"persist", "remove"}, orphanRemoval=true)
*/
@@ -394,7 +400,7 @@ class AccompanyingPeriod implements
* @ORM\OneToMany(targetEntity=UserHistory::class, mappedBy="accompanyingPeriod", orphanRemoval=true,
* cascade={"persist", "remove"})
*
* @var Collection|UserHistory[]
* @var Collection<UserHistory>
*/
private Collection $userHistories;
@@ -408,6 +414,7 @@ class AccompanyingPeriod implements
private ?User $userPrevious = null;
/**
* @var Collection<AccompanyingPeriodWork>
* @ORM\OneToMany(
* targetEntity=AccompanyingPeriodWork::class,
* mappedBy="accompanyingPeriod"
@@ -812,7 +819,7 @@ class AccompanyingPeriod implements
return 'none';
}
public function getNextCalendarsForPerson(Person $person, $limit = 5): Collection
public function getNextCalendarsForPerson(Person $person, $limit = 5): ReadableCollection
{
$today = new DateTimeImmutable('today');
$criteria = Criteria::create()

View File

@@ -102,6 +102,7 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues
private ?DateTimeImmutable $endDate = null;
/**
* @var Collection<AccompanyingPeriodWorkGoal>
* @ORM\OneToMany(
* targetEntity=AccompanyingPeriodWorkGoal::class,
* mappedBy="accompanyingPeriodWork",
@@ -137,6 +138,7 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues
private string $note = '';
/**
* @var Collection<Person>
* @ORM\ManyToMany(targetEntity=Person::class)
* @ORM\JoinTable(name="chill_person_accompanying_period_work_person")
* @Serializer\Groups({"read", "docgen:read", "read:accompanyingPeriodWork:light"})
@@ -152,6 +154,7 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues
private PrivateCommentEmbeddable $privateComment;
/**
* @var Collection<User>
* @ORM\ManyToMany(targetEntity=User::class)
* @ORM\JoinTable(name="chill_person_accompanying_period_work_referrer")
* @Serializer\Groups({"read", "docgen:read", "read:accompanyingPeriodWork:light"})
@@ -161,6 +164,7 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues
private Collection $referrers;
/**
* @var Collection<Result>
* @ORM\ManyToMany(targetEntity=Result::class, inversedBy="accompanyingPeriodWorks")
* @ORM\JoinTable(name="chill_person_accompanying_period_work_result")
* @Serializer\Groups({"read", "docgen:read"})
@@ -185,6 +189,7 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues
private ?DateTimeImmutable $startDate = null;
/**
* @var Collection<ThirdParty>
* @ORM\ManyToMany(targetEntity=ThirdParty::class)
* @ORM\JoinTable(name="chill_person_accompanying_period_work_third_party")
*

View File

@@ -59,6 +59,7 @@ class AccompanyingPeriodWorkGoal
private ?string $note = null;
/**
* @var Collection<Result>
* @ORM\ManyToMany(targetEntity=Result::class, inversedBy="accompanyingPeriodWorkGoals")
* @ORM\JoinTable(name="chill_person_accompanying_period_work_goal_result")
* @Serializer\Groups({"accompanying_period_work:edit"})

View File

@@ -32,6 +32,7 @@ class ClosingMotive
/**
* Child Accompanying periods.
*
* @var Collection<ClosingMotive>
* @ORM\OneToMany(
* targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive",
* mappedBy="parent")

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;
}

View File

@@ -14,6 +14,7 @@ namespace Chill\PersonBundle\Entity;
use ArrayIterator;
use Chill\BudgetBundle\Entity\Charge;
use Chill\BudgetBundle\Entity\Resource;
use Chill\CalendarBundle\Entity\Calendar;
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
use Chill\MainBundle\Entity\Address;
@@ -22,6 +23,7 @@ use Chill\MainBundle\Entity\Civility;
use Chill\MainBundle\Entity\Country;
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
use Chill\MainBundle\Entity\HasCenterInterface;
use Chill\MainBundle\Entity\Language;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Validation\Constraint\PhonenumberConstraint;
use Chill\PersonBundle\Entity\Household\Household;
@@ -110,14 +112,14 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
/**
* The person's accompanying periods (when the person was accompanied by the center).
*
* @var Collection
* @var Collection<AccompanyingPeriodParticipation>
*
* @ORM\OneToMany(targetEntity=AccompanyingPeriodParticipation::class,
* mappedBy="person",
* cascade={"persist", "remove", "merge", "detach"})
* @ORM\OrderBy({"startDate": "DESC"})
*/
private $accompanyingPeriodParticipations;
private Collection $accompanyingPeriodParticipations;
/**
* The accompanying period requested by the Person.
@@ -125,14 +127,14 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* @ORM\OneToMany(targetEntity=AccompanyingPeriod::class,
* mappedBy="requestorPerson")
*
* @var AccompanyingPeriod[]|Collection
* @var Collection<AccompanyingPeriod>
*/
private Collection $accompanyingPeriodRequested;
/**
* Addresses.
*
* @var Collection
* @var Collection<Address>
*
* @ORM\ManyToMany(
* targetEntity="Chill\MainBundle\Entity\Address",
@@ -140,10 +142,10 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* @ORM\JoinTable(name="chill_person_persons_to_addresses")
* @ORM\OrderBy({"validFrom": "DESC"})
*/
private $addresses;
private Collection $addresses;
/**
* @var Collection
* @var Collection<PersonAltName>
*
* @ORM\OneToMany(
* targetEntity="Chill\PersonBundle\Entity\PersonAltName",
@@ -151,7 +153,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* cascade={"persist", "remove", "merge", "detach"},
* orphanRemoval=true)
*/
private $altNames;
private Collection $altNames;
/**
* The person's birthdate.
@@ -164,6 +166,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
private $birthdate;
/**
* @var Collection<Charge>
* @ORM\OneToMany(
* targetEntity=Charge::class,
* mappedBy="person"
@@ -172,6 +175,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
private Collection $budgetCharges;
/**
* @var Collection<Resource>
* @ORM\OneToMany(
* targetEntity=Resource::class,
* mappedBy="person"
@@ -180,6 +184,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
private Collection $budgetResources;
/**
* @var Collection<Calendar>
* @ORM\ManyToMany(
* targetEntity="Chill\CalendarBundle\Entity\Calendar",
* mappedBy="persons"
@@ -204,7 +209,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
/**
* @ORM\OneToMany(targetEntity=PersonCenterHistory::class, mappedBy="person", cascade={"persist"})
*
* @var Collection|PersonCenterHistory[]
* @var Collection<PersonCenterHistory>
*/
private Collection $centerHistory;
@@ -342,6 +347,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
/**
* Read-only field, computed by the database.
*
* @var Collection<PersonHouseholdAddress>
* @ORM\OneToMany(
* targetEntity=PersonHouseholdAddress::class,
* mappedBy="person"
@@ -355,7 +361,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* mappedBy="person"
* )
*
* @var Collection|HouseholdMember[]
* @var Collection<HouseholdMember>
*/
private Collection $householdParticipations;
@@ -446,7 +452,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
private ?int $numberOfChildren = null;
/**
* @var Collection
* @var Collection<PersonPhone>
*
* @ORM\OneToMany(
* targetEntity="Chill\PersonBundle\Entity\PersonPhone",
@@ -458,13 +464,14 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* traverse=true,
* )
*/
private $otherPhoneNumbers;
private Collection $otherPhoneNumbers;
/**
* @ORM\OneToMany(
* targetEntity=AccompanyingPeriod::class,
* mappedBy="personLocation"
* )
* @var Collection<AccompanyingPeriod>
*/
private Collection $periodLocatedOn;
@@ -499,14 +506,14 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
/**
* @ORM\OneToMany(targetEntity=PersonResource::class, mappedBy="personOwner")
*
* @var Collection|PersonResource[];
* @var Collection<PersonResource>
*/
private Collection $resources;
/**
* The person's spoken languages.
*
* @var ArrayCollection
* @var Collection<Language>
*
* @ORM\ManyToMany(targetEntity="Chill\MainBundle\Entity\Language")
* @ORM\JoinTable(
@@ -515,7 +522,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* inverseJoinColumns={@ORM\JoinColumn(name="language_id", referencedColumnName="id")}
* )
*/
private $spokenLanguages;
private Collection $spokenLanguages;
/**
* @ORM\Column(type="datetime", nullable=true, options={"default": NULL})
@@ -1361,7 +1368,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
/**
* Get spokenLanguages.
*
* @return ArrayCollection
* @return Collection<Language>
*/
public function getSpokenLanguages()
{

View File

@@ -52,6 +52,7 @@ class Evaluation
private ?DateInterval $notificationDelay = null;
/**
* @var Collection<SocialAction>
* @ORM\ManyToMany(
* targetEntity=SocialAction::class,
* mappedBy="evaluations"

View File

@@ -43,12 +43,14 @@ class Goal
private ?int $id = null;
/**
* @var Collection<Result>
* @ORM\ManyToMany(targetEntity=Result::class, inversedBy="goals")
* @ORM\JoinTable(name="chill_person_social_work_goal_result")
*/
private Collection $results;
/**
* @var Collection<SocialAction>
* @ORM\ManyToMany(targetEntity=SocialAction::class, mappedBy="goals")
*/
private Collection $socialActions;

View File

@@ -33,11 +33,13 @@ use Symfony\Component\Serializer\Annotation as Serializer;
class Result
{
/**
* @var Collection<AccompanyingPeriodWorkGoal>
* @ORM\ManyToMany(targetEntity=AccompanyingPeriodWorkGoal::class, mappedBy="results")
*/
private Collection $accompanyingPeriodWorkGoals;
/**
* @var Collection<AccompanyingPeriodWork>
* @ORM\ManyToMany(targetEntity=AccompanyingPeriodWork::class, mappedBy="results")
*/
private Collection $accompanyingPeriodWorks;
@@ -48,6 +50,7 @@ class Result
private ?DateTime $desactivationDate = null;
/**
* @var Collection<Goal>
* @ORM\ManyToMany(targetEntity=Goal::class, mappedBy="results")
*/
private Collection $goals;
@@ -61,6 +64,7 @@ class Result
private ?int $id = null;
/**
* @var Collection<SocialAction>
* @ORM\ManyToMany(targetEntity=SocialAction::class, mappedBy="results")
*/
private Collection $socialActions;

View File

@@ -32,9 +32,10 @@ use Symfony\Component\Serializer\Annotation as Serializer;
class SocialAction
{
/**
* @var Collection<SocialAction>
* @ORM\OneToMany(targetEntity=SocialAction::class, mappedBy="parent")
*/
private $children;
private Collection $children;
/**
* @ORM\Column(type="dateinterval", nullable=true)
@@ -47,16 +48,18 @@ class SocialAction
private $desactivationDate;
/**
* @var Collection<Evaluation>
* @ORM\ManyToMany(targetEntity=Evaluation::class, inversedBy="socialActions")
* @ORM\JoinTable(name="chill_person_social_work_evaluation_action")
*/
private Collection $evaluations;
/**
* @var Collection<Goal>
* @ORM\ManyToMany(targetEntity=Goal::class, inversedBy="socialActions")
* @ORM\JoinTable(name="chill_person_social_action_goal")
*/
private $goals;
private Collection $goals;
/**
* @ORM\Id
@@ -81,10 +84,11 @@ class SocialAction
private $parent;
/**
* @var Collection<Result>
* @ORM\ManyToMany(targetEntity=Result::class, inversedBy="socialActions")
* @ORM\JoinTable(name="chill_person_social_action_result")
*/
private $results;
private Collection $results;
/**
* @ORM\Column(type="json")

View File

@@ -28,9 +28,10 @@ use Symfony\Component\Serializer\Annotation\Groups;
class SocialIssue
{
/**
* @var Collection<SocialIssue>
* @ORM\OneToMany(targetEntity=SocialIssue::class, mappedBy="parent")
*/
private $children;
private Collection $children;
/**
* @ORM\Column(type="datetime", nullable=true)
@@ -55,9 +56,10 @@ class SocialIssue
private $parent;
/**
* @var Collection<SocialAction>
* @ORM\OneToMany(targetEntity=SocialAction::class, mappedBy="issue")
*/
private $socialActions;
private Collection $socialActions;
/**
* @ORM\Column(type="json")