From 9d34968b8803a08c0a90a3db9f2bb8f4b7a04a36 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Fri, 14 May 2021 09:58:56 +0200 Subject: [PATCH 1/4] Fix `::getParticipationsContainsPerson`. 1. `::getParticipations()` does not accept any argument. 2. The filter predicate must return a boolean. --- .../ChillPersonBundle/Entity/AccompanyingPeriod.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index 8ec017c07..1d5f00c1f 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -348,12 +348,13 @@ class AccompanyingPeriod */ 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(); } - }); + ); } /** From a6e0b16032e2399456b975cec5f05eceb2218ef0 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Fri, 14 May 2021 10:27:07 +0200 Subject: [PATCH 2/4] Fix `::getOpenParticipationContainsPerson` 1. The filter predicate must return a boolean 2. The $person variable is not needed --- .../ChillPersonBundle/Entity/AccompanyingPeriod.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index 1d5f00c1f..f2161c78a 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -364,12 +364,13 @@ class AccompanyingPeriod */ 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; } From 484259c8abfd18b5ea86c1527241931e4d565b4f Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Fri, 14 May 2021 10:43:21 +0200 Subject: [PATCH 3/4] Fix `::canBeReOpened`. 1. Fix call to `::getOpenParticipationContainsPerson` instead of `::getParticipationsContainsPerson`. 2. Use early returns to reduce cyclomatic complexity. 3. Avoid storing variable that are used only once. --- .../ChillPersonBundle/Entity/AccompanyingPeriod.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index f2161c78a..567e678e1 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -435,15 +435,16 @@ class AccompanyingPeriod 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; } /** From 7595d70ada4bafd4463d01bb4abc9fc91151b172 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Fri, 14 May 2021 10:52:31 +0200 Subject: [PATCH 4/4] Fix `::getPersons`. 1. Add more typing informations. --- .../Entity/AccompanyingPeriod.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index 567e678e1..0f78ee2bb 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -653,13 +653,17 @@ class AccompanyingPeriod /** * 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(); + } + ); } }