From 85e2466611fc08bc180d995eed468daba4888378 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 27 Aug 2024 15:57:10 +0200 Subject: [PATCH] Cherry-pick phpstan fixes after rector changes --- .../ChillCalendarBundle/Entity/Calendar.php | 10 ++--- src/Bundle/ChillEventBundle/Entity/Event.php | 2 +- src/Bundle/ChillMainBundle/Entity/User.php | 14 +++---- .../Entity/Workflow/EntityWorkflow.php | 16 +++++--- .../Entity/AccompanyingPeriod.php | 38 +++++++++---------- .../Entity/Household/Household.php | 21 +++++----- .../ChillPersonBundle/Entity/Person.php | 32 ++++++++-------- 7 files changed, 69 insertions(+), 64 deletions(-) diff --git a/src/Bundle/ChillCalendarBundle/Entity/Calendar.php b/src/Bundle/ChillCalendarBundle/Entity/Calendar.php index 53949d1f0..294783704 100644 --- a/src/Bundle/ChillCalendarBundle/Entity/Calendar.php +++ b/src/Bundle/ChillCalendarBundle/Entity/Calendar.php @@ -103,7 +103,7 @@ class Calendar implements TrackCreationInterface, TrackUpdateInterface, HasCente private int $dateTimeVersion = 0; /** - * @var Collection + * @var Collection */ #[ORM\OneToMany(mappedBy: 'calendar', targetEntity: CalendarDoc::class, orphanRemoval: true)] private Collection $documents; @@ -120,12 +120,12 @@ class Calendar implements TrackCreationInterface, TrackUpdateInterface, HasCente private ?int $id = null; /** - * @var Collection&Selectable + * @var ArrayCollection */ #[Serializer\Groups(['read', 'docgen:read'])] #[ORM\OneToMany(mappedBy: 'calendar', targetEntity: Invite::class, cascade: ['persist', 'remove', 'merge', 'detach'], orphanRemoval: true)] #[ORM\JoinTable(name: 'chill_calendar.calendar_to_invites')] - private Collection&Selectable $invites; + private Collection $invites; #[Serializer\Groups(['read', 'docgen:read'])] #[Assert\NotNull(message: 'calendar.A location is required')] @@ -143,7 +143,7 @@ class Calendar implements TrackCreationInterface, TrackUpdateInterface, HasCente private ?Person $person = null; /** - * @var Collection + * @var Collection */ #[Serializer\Groups(['calendar:read', 'read', 'calendar:light', 'docgen:read'])] #[Assert\Count(min: 1, minMessage: 'calendar.At least {{ limit }} person is required.')] @@ -157,7 +157,7 @@ class Calendar implements TrackCreationInterface, TrackUpdateInterface, HasCente private PrivateCommentEmbeddable $privateComment; /** - * @var Collection + * @var Collection */ #[Serializer\Groups(['calendar:read', 'read', 'calendar:light', 'docgen:read'])] #[ORM\ManyToMany(targetEntity: ThirdParty::class)] diff --git a/src/Bundle/ChillEventBundle/Entity/Event.php b/src/Bundle/ChillEventBundle/Entity/Event.php index 4a3b4cd67..ef8e78065 100644 --- a/src/Bundle/ChillEventBundle/Entity/Event.php +++ b/src/Bundle/ChillEventBundle/Entity/Event.php @@ -192,7 +192,7 @@ class Event implements HasCenterInterface, HasScopeInterface, TrackCreationInter { $iterator = iterator_to_array($this->participations->getIterator()); - uasort($iterator, static fn ($first, $second) => strnatcasecmp((string) $first->getPerson()->getFirstName(), (string) $second->getPerson()->getFirstName())); + uasort($iterator, static fn ($first, $second) => strnatcasecmp($first->getPerson()->getFirstName(), $second->getPerson()->getFirstName())); return new \ArrayIterator($iterator); } diff --git a/src/Bundle/ChillMainBundle/Entity/User.php b/src/Bundle/ChillMainBundle/Entity/User.php index f2f299b7f..ce7a9935b 100644 --- a/src/Bundle/ChillMainBundle/Entity/User.php +++ b/src/Bundle/ChillMainBundle/Entity/User.php @@ -64,7 +64,7 @@ class User implements UserInterface, \Stringable, PasswordAuthenticatedUserInter private bool $enabled = true; /** - * @var Collection + * @var Collection */ #[ORM\ManyToMany(targetEntity: GroupCenter::class, inversedBy: 'users')] #[ORM\Cache(usage: 'NONSTRICT_READ_WRITE')] @@ -83,10 +83,10 @@ class User implements UserInterface, \Stringable, PasswordAuthenticatedUserInter private ?Location $mainLocation = null; /** - * @var Collection&Selectable + * @var ArrayCollection */ - #[ORM\OneToMany(targetEntity: UserScopeHistory::class, mappedBy: 'user', cascade: ['persist', 'remove'], orphanRemoval: true)] - private Collection&Selectable $scopeHistories; + #[ORM\OneToMany(mappedBy: 'user', targetEntity: UserScopeHistory::class, cascade: ['persist', 'remove'], orphanRemoval: true)] + private ArrayCollection $scopeHistories; #[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, length: 255)] private string $password = ''; @@ -98,10 +98,10 @@ class User implements UserInterface, \Stringable, PasswordAuthenticatedUserInter private ?string $salt = null; /** - * @var Collection&Selectable + * @var ArrayCollection */ - #[ORM\OneToMany(targetEntity: UserJobHistory::class, mappedBy: 'user', cascade: ['persist', 'remove'], orphanRemoval: true)] - private Collection&Selectable $jobHistories; + #[ORM\OneToMany(mappedBy: 'user', targetEntity: UserJobHistory::class, cascade: ['persist', 'remove'], orphanRemoval: true)] + private ArrayCollection $jobHistories; #[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, length: 80)] private string $username = ''; diff --git a/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php b/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php index 6df054b61..8661895d8 100644 --- a/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php +++ b/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php @@ -21,6 +21,7 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Order; use Doctrine\ORM\Mapping as ORM; +use Exception; use Symfony\Component\Serializer\Annotation as Serializer; use Symfony\Component\Validator\Constraints as Assert; @@ -64,7 +65,7 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface public array $futureDestUsers = []; /** - * @var Collection + * @var Collection */ #[ORM\OneToMany(targetEntity: EntityWorkflowComment::class, mappedBy: 'entityWorkflow', orphanRemoval: true)] private Collection $comments; @@ -81,12 +82,12 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface private int $relatedEntityId; /** - * @var Collection + * @var ArrayCollection */ #[Assert\Valid(traverse: true)] - #[ORM\OneToMany(targetEntity: EntityWorkflowStep::class, mappedBy: 'entityWorkflow', orphanRemoval: true, cascade: ['persist'])] + #[ORM\OneToMany(mappedBy: 'entityWorkflow', targetEntity: EntityWorkflowStep::class, cascade: ['persist'], orphanRemoval: true)] #[ORM\OrderBy(['transitionAt' => \Doctrine\Common\Collections\Criteria::ASC, 'id' => 'ASC'])] - private Collection $steps; + private ArrayCollection $steps; /** * @var array|EntityWorkflowStep[]|null @@ -94,14 +95,14 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface private ?array $stepsChainedCache = null; /** - * @var Collection + * @var Collection */ #[ORM\ManyToMany(targetEntity: User::class)] #[ORM\JoinTable(name: 'chill_main_workflow_entity_subscriber_to_final')] private Collection $subscriberToFinal; /** - * @var Collection + * @var Collection */ #[ORM\ManyToMany(targetEntity: User::class)] #[ORM\JoinTable(name: 'chill_main_workflow_entity_subscriber_to_step')] @@ -276,6 +277,9 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface return $this->steps; } + /** + * @throws Exception + */ public function getStepsChained(): array { if (\is_array($this->stepsChainedCache)) { diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index 21cdaaf37..c9bf05fdb 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -135,14 +135,14 @@ class AccompanyingPeriod implements private ?Location $administrativeLocation = null; /** - * @var Collection&Selectable + * @var ArrayCollection */ - #[ORM\OneToMany(targetEntity: Calendar::class, mappedBy: 'accompanyingPeriod')] - private Collection&Selectable $calendars; + #[ORM\OneToMany(mappedBy: 'accompanyingPeriod', targetEntity: Calendar::class)] + private ArrayCollection $calendars; #[Groups(['read', 'write', 'docgen:read'])] #[Assert\NotBlank(groups: [AccompanyingPeriod::STEP_CLOSED])] - #[Assert\GreaterThanOrEqual(propertyPath: 'openingDate', groups: [AccompanyingPeriod::STEP_CLOSED], message: 'The closing date must be later than the date of creation')] + #[Assert\GreaterThanOrEqual(propertyPath: 'openingDate', message: 'The closing date must be later than the date of creation', groups: [AccompanyingPeriod::STEP_CLOSED])] #[ORM\Column(type: \Doctrine\DBAL\Types\Types::DATE_MUTABLE, nullable: true)] private ?\DateTime $closingDate = null; @@ -153,10 +153,10 @@ class AccompanyingPeriod implements private ?ClosingMotive $closingMotive = null; /** - * @var Collection + * @var Collection<(int|string), Comment> */ #[Assert\NotBlank(groups: [AccompanyingPeriod::STEP_DRAFT])] - #[ORM\OneToMany(targetEntity: Comment::class, mappedBy: 'accompanyingPeriod', cascade: ['persist', 'remove'], orphanRemoval: true)] + #[ORM\OneToMany(mappedBy: 'accompanyingPeriod', targetEntity: Comment::class, cascade: ['persist', 'remove'], orphanRemoval: true)] #[ORM\OrderBy(['createdAt' => Criteria::DESC, 'id' => 'DESC'])] private Collection $comments; @@ -194,9 +194,9 @@ class AccompanyingPeriod implements private ?UserJob $job = null; /** - * @var Collection + * @var Collection */ - #[ORM\OneToMany(targetEntity: AccompanyingPeriodLocationHistory::class, mappedBy: 'period', cascade: ['persist', 'remove'], orphanRemoval: true)] + #[ORM\OneToMany(mappedBy: 'period', targetEntity: AccompanyingPeriodLocationHistory::class, cascade: ['persist', 'remove'], orphanRemoval: true)] private Collection $locationHistories; #[Groups(['read', 'write', 'docgen:read'])] @@ -212,10 +212,10 @@ class AccompanyingPeriod implements private ?Origin $origin = null; /** - * @var Collection + * @var Collection */ #[Groups(['read', 'docgen:read'])] - #[ORM\OneToMany(targetEntity: AccompanyingPeriodParticipation::class, mappedBy: 'accompanyingPeriod', orphanRemoval: true, cascade: ['persist', 'refresh', 'remove', 'merge', 'detach'])] + #[ORM\OneToMany(mappedBy: 'accompanyingPeriod', targetEntity: AccompanyingPeriodParticipation::class, cascade: ['persist', 'refresh', 'remove', 'merge', 'detach'], orphanRemoval: true)] #[ParticipationOverlap(groups: [AccompanyingPeriod::STEP_DRAFT, AccompanyingPeriod::STEP_CONFIRMED])] private Collection $participations; @@ -246,7 +246,7 @@ class AccompanyingPeriod implements private ?ThirdParty $requestorThirdParty = null; /** - * @var Collection + * @var Collection */ #[Groups(['read', 'docgen:read'])] #[ORM\OneToMany(targetEntity: AccompanyingPeriod\Resource::class, mappedBy: 'accompanyingPeriod', cascade: ['persist', 'remove'], orphanRemoval: true)] @@ -254,7 +254,7 @@ class AccompanyingPeriod implements private Collection $resources; /** - * @var Collection + * @var Collection */ #[Groups(['read', 'docgen:read'])] #[Assert\Count(min: 1, groups: [AccompanyingPeriod::STEP_CONFIRMED], minMessage: 'A course must be associated to at least one scope')] @@ -263,7 +263,7 @@ class AccompanyingPeriod implements private Collection $scopes; /** - * @var Collection + * @var Collection */ #[Groups(['read', 'docgen:read'])] #[Assert\Count(min: 1, groups: [AccompanyingPeriod::STEP_CONFIRMED], minMessage: 'A course must contains at least one social issue')] @@ -279,9 +279,9 @@ class AccompanyingPeriod implements private ?string $step = self::STEP_DRAFT; /** - * @var Collection + * @var Collection */ - #[ORM\OneToMany(targetEntity: AccompanyingPeriodStepHistory::class, mappedBy: 'period', cascade: ['persist', 'remove'], orphanRemoval: true)] + #[ORM\OneToMany(mappedBy: 'period', targetEntity: AccompanyingPeriodStepHistory::class, cascade: ['persist', 'remove'], orphanRemoval: true)] private Collection $stepHistories; #[ORM\Column(type: \Doctrine\DBAL\Types\Types::DATETIME_MUTABLE, nullable: true, options: ['default' => null])] @@ -296,7 +296,7 @@ class AccompanyingPeriod implements private ?User $user = null; /** - * @var Collection + * @var Collection */ #[ORM\OneToMany(targetEntity: UserHistory::class, mappedBy: 'accompanyingPeriod', orphanRemoval: true, cascade: ['persist', 'remove'])] private Collection $userHistories; @@ -311,10 +311,10 @@ class AccompanyingPeriod implements private ?User $userPrevious = null; /** - * @var Collection + * @var Collection */ #[Assert\Valid(traverse: true)] - #[ORM\OneToMany(targetEntity: AccompanyingPeriodWork::class, mappedBy: 'accompanyingPeriod')] + #[ORM\OneToMany(mappedBy: 'accompanyingPeriod', targetEntity: AccompanyingPeriodWork::class)] private Collection $works; /** @@ -801,7 +801,7 @@ class AccompanyingPeriod implements /** * Get a list of all persons which are participating to this course. * - * @psalm-return Collection<(int|string), Person|null> + * @psalm-return Collection */ public function getPersons(): Collection { diff --git a/src/Bundle/ChillPersonBundle/Entity/Household/Household.php b/src/Bundle/ChillPersonBundle/Entity/Household/Household.php index dbc1769f5..719baddaf 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Household/Household.php +++ b/src/Bundle/ChillPersonBundle/Entity/Household/Household.php @@ -21,6 +21,7 @@ use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Criteria; use Doctrine\Common\Collections\ReadableCollection; use Doctrine\Common\Collections\Selectable; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Annotation as Serializer; use Symfony\Component\Validator\Constraints as Assert; @@ -35,7 +36,7 @@ class Household implements HasCentersInterface /** * Addresses. * - * @var Collection
+ * @var Collection */ #[Serializer\Groups(['write'])] #[ORM\ManyToMany(targetEntity: Address::class, cascade: ['persist', 'remove', 'merge', 'detach'])] @@ -47,33 +48,33 @@ class Household implements HasCentersInterface private CommentEmbeddable $commentMembers; /** - * @var Collection&Selectable + * @var ArrayCollection */ - #[Assert\Valid(traverse: true, groups: ['household_composition'])] - #[ORM\OneToMany(targetEntity: HouseholdComposition::class, mappedBy: 'household', orphanRemoval: true, cascade: ['persist'])] + #[Assert\Valid(groups: ['household_composition'], traverse: true)] + #[ORM\OneToMany(mappedBy: 'household', targetEntity: HouseholdComposition::class, cascade: ['persist'], orphanRemoval: true)] #[ORM\OrderBy(['startDate' => Criteria::DESC])] - private Collection&Selectable $compositions; + private ArrayCollection $compositions; #[Serializer\Groups(['read', 'docgen:read'])] #[ORM\Id] #[ORM\GeneratedValue] - #[ORM\Column(type: \Doctrine\DBAL\Types\Types::INTEGER)] + #[ORM\Column(type: Types::INTEGER)] private ?int $id = null; /** - * @var Collection + * @var Collection */ #[Serializer\Groups(['read', 'docgen:read'])] - #[ORM\OneToMany(targetEntity: HouseholdMember::class, mappedBy: 'household')] + #[ORM\OneToMany(mappedBy: 'household', targetEntity: HouseholdMember::class)] private Collection $members; #[Serializer\Groups(['docgen:read'])] - #[ORM\Column(type: \Doctrine\DBAL\Types\Types::BOOLEAN, name: 'waiting_for_birth', options: ['default' => false])] + #[ORM\Column(name: 'waiting_for_birth', type: Types::BOOLEAN, options: ['default' => false])] #[Assert\Type('boolean', groups: ['household_metadata'])] private bool $waitingForBirth = false; #[Serializer\Groups(['docgen:read'])] - #[ORM\Column(type: \Doctrine\DBAL\Types\Types::DATE_IMMUTABLE, name: 'waiting_for_birth_date', nullable: true, options: ['default' => null])] + #[ORM\Column(type: Types::DATE_IMMUTABLE, name: 'waiting_for_birth_date', nullable: true, options: ['default' => null])] #[Assert\Expression('this.getWaitingForBirth() == false or value != null', message: 'The waiting for birth date must be set', groups: ['household_metadata'])] private ?\DateTimeImmutable $waitingForBirthDate = null; diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index ff9e799a3..5d4486179 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -86,7 +86,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI /** * The person's accompanying periods (when the person was accompanied by the center). * - * @var Collection + * @var Collection */ #[ORM\OneToMany(targetEntity: AccompanyingPeriodParticipation::class, mappedBy: 'person', cascade: ['persist', 'remove', 'merge', 'detach'])] #[ORM\OrderBy(['startDate' => Criteria::DESC])] @@ -95,7 +95,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI /** * The accompanying period requested by the Person. * - * @var Collection + * @var Collection */ #[ORM\OneToMany(targetEntity: AccompanyingPeriod::class, mappedBy: 'requestorPerson')] private Collection $accompanyingPeriodRequested; @@ -103,7 +103,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI /** * Addresses. * - * @var Collection
+ * @var Collection */ #[ORM\ManyToMany(targetEntity: Address::class, cascade: ['persist', 'remove', 'merge', 'detach'])] #[ORM\JoinTable(name: 'chill_person_persons_to_addresses')] @@ -111,7 +111,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI private Collection $addresses; /** - * @var Collection + * @var Collection */ #[ORM\OneToMany(targetEntity: PersonAltName::class, mappedBy: 'person', cascade: ['persist', 'remove', 'merge', 'detach'], orphanRemoval: true)] private Collection $altNames; @@ -124,13 +124,13 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI private ?\DateTime $birthdate = null; /** - * @var Collection + * @var Collection */ #[ORM\OneToMany(targetEntity: Charge::class, mappedBy: 'person')] private Collection $budgetCharges; /** - * @var Collection + * @var Collection */ #[ORM\OneToMany(targetEntity: Resource::class, mappedBy: 'person')] private Collection $budgetResources; @@ -149,14 +149,14 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI #[ORM\ManyToOne(targetEntity: Center::class)] private ?Center $center = null; - #[ORM\OneToOne(targetEntity: PersonCenterCurrent::class, mappedBy: 'person')] + #[ORM\OneToOne(mappedBy: 'person', targetEntity: PersonCenterCurrent::class)] private ?PersonCenterCurrent $centerCurrent = null; /** - * @var Collection + * @var ArrayCollection */ - #[ORM\OneToMany(targetEntity: PersonCenterHistory::class, mappedBy: 'person', cascade: ['persist', 'remove'])] - private Collection $centerHistory; + #[ORM\OneToMany(mappedBy: 'person', targetEntity: PersonCenterHistory::class, cascade: ['persist', 'remove'])] + private ArrayCollection $centerHistory; /** * Array where customfield's data are stored. @@ -256,13 +256,13 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI /** * Read-only field, computed by the database. * - * @var Collection + * @var Collection */ #[ORM\OneToMany(targetEntity: PersonHouseholdAddress::class, mappedBy: 'person')] private Collection $householdAddresses; /** - * @var Collection + * @var Collection */ #[ORM\OneToMany(targetEntity: HouseholdMember::class, mappedBy: 'person')] private Collection $householdParticipations; @@ -330,14 +330,14 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI private ?int $numberOfChildren = null; /** - * @var Collection + * @var Collection */ #[Assert\Valid(traverse: true)] #[ORM\OneToMany(targetEntity: PersonPhone::class, mappedBy: 'person', cascade: ['persist', 'remove', 'merge', 'detach'], orphanRemoval: true)] private Collection $otherPhoneNumbers; /** - * @var Collection + * @var Collection */ #[ORM\OneToMany(targetEntity: AccompanyingPeriod::class, mappedBy: 'personLocation')] private Collection $periodLocatedOn; @@ -361,7 +361,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI #[ORM\Column(type: \Doctrine\DBAL\Types\Types::BOOLEAN)] private bool $proxyAccompanyingPeriodOpenState = false; // TO-DELETE ? /** - * @var Collection + * @var Collection */ #[ORM\OneToMany(targetEntity: PersonResource::class, mappedBy: 'personOwner')] private Collection $resources; @@ -1633,7 +1633,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI } /** - * @param (\Doctrine\Common\Collections\Collection) $spokenLanguages + * @param (Collection) $spokenLanguages */ public function setSpokenLanguages(Collection $spokenLanguages): self {