diff --git a/src/Bundle/ChillPersonBundle/Config/ConfigPersonAltNamesHelper.php b/src/Bundle/ChillPersonBundle/Config/ConfigPersonAltNamesHelper.php index ae291067b..7226e96c9 100644 --- a/src/Bundle/ChillPersonBundle/Config/ConfigPersonAltNamesHelper.php +++ b/src/Bundle/ChillPersonBundle/Config/ConfigPersonAltNamesHelper.php @@ -11,8 +11,6 @@ declare(strict_types=1); namespace Chill\PersonBundle\Config; -use function count; - /** * Give help to interact with the config for alt names. */ @@ -69,6 +67,6 @@ class ConfigPersonAltNamesHelper */ public function hasAltNames(): bool { - return count($this->config) > 0; + return [] !== $this->config; } } diff --git a/src/Bundle/ChillPersonBundle/Controller/PersonApiController.php b/src/Bundle/ChillPersonBundle/Controller/PersonApiController.php index 813ccee2a..6e77ae69e 100644 --- a/src/Bundle/ChillPersonBundle/Controller/PersonApiController.php +++ b/src/Bundle/ChillPersonBundle/Controller/PersonApiController.php @@ -15,6 +15,7 @@ use Chill\MainBundle\CRUD\Controller\ApiController; use Chill\MainBundle\Entity\Address; use Chill\MainBundle\Security\Authorization\AuthorizationHelper; use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper; +use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Security\Authorization\PersonVoter; use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; @@ -22,9 +23,6 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; -use function array_filter; -use function array_values; - class PersonApiController extends ApiController { private AuthorizationHelper $authorizationHelper; @@ -56,8 +54,10 @@ class PersonApiController extends ApiController static fn (array $data, string $key): array => ['key' => $key, 'labels' => $data], $configAltNamesChoices, array_keys($configAltNamesChoices) - ), - Response::HTTP_OK, [], ['groups' => ['read']] + ), + Response::HTTP_OK, + [], + ['groups' => ['read']] ); } @@ -79,23 +79,32 @@ class PersonApiController extends ApiController { $this->denyAccessUnlessGranted(PersonVoter::SEE, $person); - $addresses = []; // collect addresses from location in courses - foreach ($person->getAccompanyingPeriodParticipations() as $participation) { - if (null !== $participation->getAccompanyingPeriod()->getAddressLocation()) { - $a = $participation->getAccompanyingPeriod()->getAddressLocation(); - $addresses[$a->getId()] = $a; - } - } + $addresses = $person + ->getAccompanyingPeriodParticipations() + ->filter( + static function (AccompanyingPeriodParticipation $accompanyingPeriodParticipation): bool { + return null !== $accompanyingPeriodParticipation->getAccompanyingPeriod()->getAddressLocation(); + } + ) + ->map( + static function (AccompanyingPeriodParticipation $accompanyingPeriodParticipation): ?Address { + return $accompanyingPeriodParticipation->getAccompanyingPeriod()->getAddressLocation(); + } + ); // remove the actual address $actual = $person->getCurrentHouseholdAddress(); if (null !== $actual) { - $addresses = array_filter($addresses, static fn ($a) => $a !== $actual); + $addresses = $addresses->filter(static fn (?Address $address): bool => $address !== $actual); } - return $this->json(array_values($addresses), Response::HTTP_OK, [], ['groups' => ['read']]); + return $this->json( + $addresses->getValues(), + Response::HTTP_OK, + [], + ['groups' => ['read']] + ); } - } diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php index d1a9143dc..8d23f8974 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonJsonNormalizer.php @@ -212,7 +212,10 @@ class PersonJsonNormalizer implements return $altNames ->map( static function (PersonAltName $personAltName): array { - return ['key' => $personAltName->getKey(), 'label' => $personAltName->getLabel()]; + return [ + 'key' => $personAltName->getKey(), + 'label' => $personAltName->getLabel(), + ]; } ) ->toArray();