| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- declare(strict_types=1);
- namespace App\Service\Core;
- use App\Entity\Access\Access;
- use App\Entity\Core\ContactPoint;
- use App\Enum\Core\ContactPointTypeEnum;
- use App\Repository\Core\ContactPointRepository;
- use App\Test\Service\Access\ContactPointUtilsTest;
- /**
- * Classe ContactPointUtils qui possédant les fonctions utils à l'entité ContactPoint
- */
- class ContactPointUtils
- {
- public function __construct(private ContactPointRepository $contactPointRepository){
- }
- /**
- * Renvoie le point de contact principal de l'Access, ou null si aucun trouvé.
- *
- * @param Access $access
- * @return ContactPoint|null
- * @throws \Exception
- * @see ContactPointUtilsTest::testGetPersonContactPointPrincipal()
- */
- public function getPersonContactPointPrincipal(Access $access): ?ContactPoint {
- $contactPoints = $this->contactPointRepository->getByTypeAndPerson(
- ContactPointTypeEnum::PRINCIPAL()->getValue(),
- $access->getPerson()
- );
- if (count($contactPoints) === 0) {
- return null;
- }
- if (count($contactPoints) !== 1){
- throw new \RuntimeException('more_than_one_result');
- }
- return $contactPoints[0];
- }
- }
|