diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index 9841a99f3..c90f8b4f9 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -447,12 +447,13 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface */ public function getParticipationsContainsPerson(Person $person): Collection { - return $this->getParticipations($person)->filter( - function(AccompanyingPeriodParticipation $participation) use ($person) { - if ($person === $participation->getPerson()) { - return $participation; + return $this + ->getParticipations() + ->filter( + static function(AccompanyingPeriodParticipation $participation) use ($person): bool { + return $person === $participation->getPerson(); } - }); + ); } /** @@ -462,12 +463,13 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface */ public function getOpenParticipationContainsPerson(Person $person): ?AccompanyingPeriodParticipation { - $collection = $this->getParticipationsContainsPerson($person)->filter( - function(AccompanyingPeriodParticipation $participation) use ($person) { - if (NULL === $participation->getEndDate()) { - return $participation; + $collection = $this + ->getParticipationsContainsPerson($person) + ->filter( + static function(AccompanyingPeriodParticipation $participation): bool { + return null === $participation->getEndDate(); } - }); + ); return $collection->count() > 0 ? $collection->first() : NULL; } @@ -557,15 +559,16 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface return false; } - $participation = $this->getParticipationsContainsPerson($person); - if (!null === $participation) + $participation = $this->getOpenParticipationContainsPerson($person); + + if (null === $participation) { - $person = $participation->getPerson(); - $periods = $person->getAccompanyingPeriodsOrdered(); - return end($periods) === $this; + return false; } - return false; + $periods = $participation->getPerson()->getAccompanyingPeriodsOrdered(); + + return end($periods) === $this; } /** @@ -825,14 +828,18 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface /** * Get a list of all persons which are participating to this course + * + * @psalm-return Collection */ public function getPersons(): Collection { - return $this->participations->map( - function(AccompanyingPeriodParticipation $participation) { - return $participation->getPerson(); - } - ); + return $this + ->participations + ->map( + static function(AccompanyingPeriodParticipation $participation): Person { + return $participation->getPerson(); + } + ); } public function setCreatedAt(\DateTimeInterface $datetime): self