Olivier Massot hai 1 ano
pai
achega
9594a68603

+ 34 - 13
src/ApiResources/Organization/OrganizationCreationRequest.php

@@ -13,7 +13,7 @@ use App\State\Processor\Organization\OrganizationCreationRequestProcessor;
 use Symfony\Component\Validator\Constraints as Assert;
 
 /**
- * Requête de création d'une nouvelle organisation
+ * Requête de création d'une nouvelle organisation.
  */
 #[ApiResource(
     operations: [
@@ -40,7 +40,6 @@ class OrganizationCreationRequest
 
     /**
      * A quelle adresse email notifier la création de l'organisation, ou d'éventuelles erreurs ?
-     * @var string|null
      */
     #[Assert\Email(message: 'The email {{ value }} is not a valid email.')]
     private ?string $sendConfirmationEmailAt = null;
@@ -48,8 +47,7 @@ class OrganizationCreationRequest
     private string $name;
 
     /**
-     * Matricule (obligatoire dans le réseau CMF)
-     * @var string
+     * Matricule (obligatoire dans le réseau CMF).
      */
     #[Assert\Regex(pattern: '/^|(FR\d{12})$/')]
     private string $identifier = '';
@@ -113,31 +111,28 @@ class OrganizationCreationRequest
     /**
      * Id d'une Person existante ou requête de création d'un nouvel access qui aura le
      * rôle de président(e) de la nouvelle structure.
-     * @var int|OrganizationMemberCreationRequest|null
      */
     private int|OrganizationMemberCreationRequest|null $president = null;
 
     /**
      * Id d'une Person existante ou requête de création d'un nouvel access qui aura le
      * rôle de directeur / directrice de la nouvelle structure.
-     * @var int|OrganizationMemberCreationRequest|null
      */
     private int|OrganizationMemberCreationRequest|null $director = null;
 
     /**
-     * Faut-il créer un site typo3 pour la nouvelle structure
-     * @var bool
+     * Faut-il créer un site typo3 pour la nouvelle structure.
      */
     private bool $createWebsite = true;
 
     /**
-     * La structure est-elle cliente de Opentalent
-     * @var bool
+     * La structure est-elle cliente de Opentalent.
      */
     private bool $client = false;
 
     /**
-     * Statut de l'opération
+     * Statut de l'opération.
+     *
      * @var int
      */
     private string $status = self::STATUS_PENDING;
@@ -146,8 +141,7 @@ class OrganizationCreationRequest
     private ?int $authorId = null;
 
     /**
-     * For testing purposes only
-     * @var bool
+     * For testing purposes only.
      */
     private bool $async = true;
 
@@ -159,6 +153,7 @@ class OrganizationCreationRequest
     public function setId(int $id): self
     {
         $this->id = $id;
+
         return $this;
     }
 
@@ -170,6 +165,7 @@ class OrganizationCreationRequest
     public function setSendConfirmationEmailAt(?string $sendConfirmationEmailAt): self
     {
         $this->sendConfirmationEmailAt = $sendConfirmationEmailAt;
+
         return $this;
     }
 
@@ -181,6 +177,7 @@ class OrganizationCreationRequest
     public function setName(string $name): self
     {
         $this->name = $name;
+
         return $this;
     }
 
@@ -192,6 +189,7 @@ class OrganizationCreationRequest
     public function setIdentifier(string $identifier): self
     {
         $this->identifier = $identifier;
+
         return $this;
     }
 
@@ -203,6 +201,7 @@ class OrganizationCreationRequest
     public function setSiretNumber(string $siretNumber): self
     {
         $this->siretNumber = $siretNumber;
+
         return $this;
     }
 
@@ -214,6 +213,7 @@ class OrganizationCreationRequest
     public function setWaldecNumber(string $waldecNumber): self
     {
         $this->waldecNumber = $waldecNumber;
+
         return $this;
     }
 
@@ -225,6 +225,7 @@ class OrganizationCreationRequest
     public function setLegalStatus(LegalEnum $legalStatus): self
     {
         $this->legalStatus = $legalStatus;
+
         return $this;
     }
 
@@ -236,6 +237,7 @@ class OrganizationCreationRequest
     public function setProduct(SettingsProductEnum $product): self
     {
         $this->product = $product;
+
         return $this;
     }
 
@@ -247,6 +249,7 @@ class OrganizationCreationRequest
     public function setStreetAddress1(string $streetAddress1): self
     {
         $this->streetAddress1 = $streetAddress1;
+
         return $this;
     }
 
@@ -258,6 +261,7 @@ class OrganizationCreationRequest
     public function setStreetAddress2(?string $streetAddress2): self
     {
         $this->streetAddress2 = $streetAddress2;
+
         return $this;
     }
 
@@ -269,6 +273,7 @@ class OrganizationCreationRequest
     public function setStreetAddress3(?string $streetAddress3): self
     {
         $this->streetAddress3 = $streetAddress3;
+
         return $this;
     }
 
@@ -280,6 +285,7 @@ class OrganizationCreationRequest
     public function setPostalCode(string $postalCode): self
     {
         $this->postalCode = $postalCode;
+
         return $this;
     }
 
@@ -291,6 +297,7 @@ class OrganizationCreationRequest
     public function setCity(string $city): self
     {
         $this->city = $city;
+
         return $this;
     }
 
@@ -302,6 +309,7 @@ class OrganizationCreationRequest
     public function setCountryId(int $countryId): self
     {
         $this->countryId = $countryId;
+
         return $this;
     }
 
@@ -313,6 +321,7 @@ class OrganizationCreationRequest
     public function setPhoneNumber(string $phoneNumber): self
     {
         $this->phoneNumber = $phoneNumber;
+
         return $this;
     }
 
@@ -324,6 +333,7 @@ class OrganizationCreationRequest
     public function setEmail(string $email): self
     {
         $this->email = $email;
+
         return $this;
     }
 
@@ -335,6 +345,7 @@ class OrganizationCreationRequest
     public function setSubdomain(string $subdomain): self
     {
         $this->subdomain = $subdomain;
+
         return $this;
     }
 
@@ -346,6 +357,7 @@ class OrganizationCreationRequest
     public function setParentId(int $parentId): self
     {
         $this->parentId = $parentId;
+
         return $this;
     }
 
@@ -357,6 +369,7 @@ class OrganizationCreationRequest
     public function setPrincipalType(PrincipalTypeEnum $principalType): self
     {
         $this->principalType = $principalType;
+
         return $this;
     }
 
@@ -368,6 +381,7 @@ class OrganizationCreationRequest
     public function setPresident(?OrganizationMemberCreationRequest $president): self
     {
         $this->president = $president;
+
         return $this;
     }
 
@@ -379,6 +393,7 @@ class OrganizationCreationRequest
     public function setDirector(?OrganizationMemberCreationRequest $director): self
     {
         $this->director = $director;
+
         return $this;
     }
 
@@ -390,6 +405,7 @@ class OrganizationCreationRequest
     public function setCreateWebsite(bool $createWebsite): self
     {
         $this->createWebsite = $createWebsite;
+
         return $this;
     }
 
@@ -401,6 +417,7 @@ class OrganizationCreationRequest
     public function setClient(bool $client): self
     {
         $this->client = $client;
+
         return $this;
     }
 
@@ -412,6 +429,7 @@ class OrganizationCreationRequest
     public function setStatus(string $status): self
     {
         $this->status = $status;
+
         return $this;
     }
 
@@ -423,6 +441,7 @@ class OrganizationCreationRequest
     public function setCreationDate(?\DateTime $creationDate): self
     {
         $this->creationDate = $creationDate;
+
         return $this;
     }
 
@@ -434,6 +453,7 @@ class OrganizationCreationRequest
     public function setAuthorId(?int $authorId): self
     {
         $this->authorId = $authorId;
+
         return $this;
     }
 
@@ -445,6 +465,7 @@ class OrganizationCreationRequest
     public function setAsync(bool $async): self
     {
         $this->async = $async;
+
         return $this;
     }
 }

+ 16 - 2
src/ApiResources/Organization/OrganizationMemberCreationRequest.php

@@ -2,12 +2,11 @@
 
 namespace App\ApiResources\Organization;
 
-
 use App\Enum\Person\GenderEnum;
 use Symfony\Component\Validator\Constraints as Assert;
 
 /**
- * Requête de création d'un nouvel access
+ * Requête de création d'un nouvel access.
  */
 class OrganizationMemberCreationRequest
 {
@@ -80,6 +79,7 @@ class OrganizationMemberCreationRequest
     public function setUsername(string $username): self
     {
         $this->username = $username;
+
         return $this;
     }
 
@@ -91,6 +91,7 @@ class OrganizationMemberCreationRequest
     public function setGender(GenderEnum $gender): self
     {
         $this->gender = $gender;
+
         return $this;
     }
 
@@ -102,6 +103,7 @@ class OrganizationMemberCreationRequest
     public function setName(string $name): self
     {
         $this->name = $name;
+
         return $this;
     }
 
@@ -113,6 +115,7 @@ class OrganizationMemberCreationRequest
     public function setGivenName(string $givenName): self
     {
         $this->givenName = $givenName;
+
         return $this;
     }
 
@@ -124,6 +127,7 @@ class OrganizationMemberCreationRequest
     public function setStreetAddress1(string $streetAddress1): self
     {
         $this->streetAddress1 = $streetAddress1;
+
         return $this;
     }
 
@@ -135,6 +139,7 @@ class OrganizationMemberCreationRequest
     public function setStreetAddress2(?string $streetAddress2): self
     {
         $this->streetAddress2 = $streetAddress2;
+
         return $this;
     }
 
@@ -146,6 +151,7 @@ class OrganizationMemberCreationRequest
     public function setStreetAddress3(?string $streetAddress3): self
     {
         $this->streetAddress3 = $streetAddress3;
+
         return $this;
     }
 
@@ -157,6 +163,7 @@ class OrganizationMemberCreationRequest
     public function setPostalCode(string $postalCode): self
     {
         $this->postalCode = $postalCode;
+
         return $this;
     }
 
@@ -168,6 +175,7 @@ class OrganizationMemberCreationRequest
     public function setCity(string $city): self
     {
         $this->city = $city;
+
         return $this;
     }
 
@@ -179,6 +187,7 @@ class OrganizationMemberCreationRequest
     public function setCountryId(int $countryId): self
     {
         $this->countryId = $countryId;
+
         return $this;
     }
 
@@ -190,6 +199,7 @@ class OrganizationMemberCreationRequest
     public function setPhone(string $phone): self
     {
         $this->phone = $phone;
+
         return $this;
     }
 
@@ -201,6 +211,7 @@ class OrganizationMemberCreationRequest
     public function setMobile(?string $mobile): self
     {
         $this->mobile = $mobile;
+
         return $this;
     }
 
@@ -212,6 +223,7 @@ class OrganizationMemberCreationRequest
     public function setEmail(string $email): self
     {
         $this->email = $email;
+
         return $this;
     }
 
@@ -223,6 +235,7 @@ class OrganizationMemberCreationRequest
     public function setCreationDate(?\DateTimeInterface $creationDate): self
     {
         $this->creationDate = $creationDate;
+
         return $this;
     }
 
@@ -234,6 +247,7 @@ class OrganizationMemberCreationRequest
     public function setAuthorId(?int $authorId): self
     {
         $this->authorId = $authorId;
+
         return $this;
     }
 }

+ 14 - 2
src/Entity/Organization/OrganizationIdentification.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace App\Entity\Organization;
@@ -10,7 +11,7 @@ use Doctrine\ORM\Mapping as ORM;
 
 /**
  * Cette entité regroupe les informations permettant d'identifier une organisation, et est utilisée entre autre
- * pour la création d'organisation
+ * pour la création d'organisation.
  *
  * Fichier source de la view : ./sql/schema-extensions/003-view_organization_identification.sql
  */
@@ -19,7 +20,7 @@ use Doctrine\ORM\Mapping as ORM;
         new Get(
             uriTemplate: '/public/organization_identification/{id}',
             requirements: ['id' => '\\d+']
-        )
+        ),
     ]
 )]
 #[ORM\Table(name: 'view_organization_identification')]
@@ -77,6 +78,7 @@ class OrganizationIdentification
     public function setId(int $id): self
     {
         $this->id = $id;
+
         return $this;
     }
 
@@ -88,6 +90,7 @@ class OrganizationIdentification
     public function setName(string $name): self
     {
         $this->name = $name;
+
         return $this;
     }
 
@@ -99,6 +102,7 @@ class OrganizationIdentification
     public function setNormalizedName(string $normalizedName): self
     {
         $this->normalizedName = $normalizedName;
+
         return $this;
     }
 
@@ -110,6 +114,7 @@ class OrganizationIdentification
     public function setIdentifier(?string $identifier): self
     {
         $this->identifier = $identifier;
+
         return $this;
     }
 
@@ -121,6 +126,7 @@ class OrganizationIdentification
     public function setSiretNumber(?string $siretNumber): self
     {
         $this->siretNumber = $siretNumber;
+
         return $this;
     }
 
@@ -132,6 +138,7 @@ class OrganizationIdentification
     public function setWaldecNumber(?string $waldecNumber): self
     {
         $this->waldecNumber = $waldecNumber;
+
         return $this;
     }
 
@@ -143,6 +150,7 @@ class OrganizationIdentification
     public function setNormalizedAddress(?string $normalizedAddress): self
     {
         $this->normalizedAddress = $normalizedAddress;
+
         return $this;
     }
 
@@ -154,6 +162,7 @@ class OrganizationIdentification
     public function setAddressCity(?string $addressCity): self
     {
         $this->addressCity = $addressCity;
+
         return $this;
     }
 
@@ -165,6 +174,7 @@ class OrganizationIdentification
     public function setPostalCode(?string $postalCode): self
     {
         $this->postalCode = $postalCode;
+
         return $this;
     }
 
@@ -176,6 +186,7 @@ class OrganizationIdentification
     public function setEmail(?string $email): self
     {
         $this->email = $email;
+
         return $this;
     }
 
@@ -187,6 +198,7 @@ class OrganizationIdentification
     public function setTelphone(?string $telphone): self
     {
         $this->telphone = $telphone;
+
         return $this;
     }
 }

+ 1 - 0
src/Entity/Organization/Parameters.php

@@ -231,6 +231,7 @@ class Parameters
         }
 
         $this->organization = $organization;
+
         return $this;
     }
 

+ 1 - 0
src/Entity/Organization/Settings.php

@@ -133,6 +133,7 @@ class Settings
     public function setCreateDate(?\DateTimeInterface $createDate): self
     {
         $this->createDate = $createDate;
+
         return $this;
     }
 }

+ 3 - 0
src/Entity/Traits/CreatedOnAndByTrait.php

@@ -1,4 +1,5 @@
 <?php
+
 declare(strict_types=1);
 
 namespace App\Entity\Traits;
@@ -24,6 +25,7 @@ trait CreatedOnAndByTrait
     public function setCreateDate(?\DateTimeInterface $createDate): self
     {
         $this->createDate = $createDate;
+
         return $this;
     }
 
@@ -35,6 +37,7 @@ trait CreatedOnAndByTrait
     public function setCreatedBy(?int $createdBy): self
     {
         $this->createdBy = $createdBy;
+
         return $this;
     }
 }

+ 1 - 1
src/Message/Command/OrganizationCreationCommand.php

@@ -12,7 +12,7 @@ use App\ApiResources\Organization\OrganizationCreationRequest;
 class OrganizationCreationCommand
 {
     public function __construct(
-        private OrganizationCreationRequest $organizationCreationRequest
+        private OrganizationCreationRequest $organizationCreationRequest,
     ) {
     }
 

+ 5 - 7
src/Message/Handler/OrganizationCreationHandler.php

@@ -11,7 +11,6 @@ use Symfony\Component\Messenger\Attribute\AsMessageHandler;
 use Symfony\Component\Mime\Address;
 use Symfony\Component\Mime\Email as SymfonyEmail;
 use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
-use Throwable;
 
 #[AsMessageHandler(priority: 1)]
 class OrganizationCreationHandler
@@ -19,10 +18,11 @@ class OrganizationCreationHandler
     public function __construct(
         private readonly OrganizationFactory $organizationFactory,
         private readonly MailerInterface $symfonyMailer,
-    ) {}
+    ) {
+    }
 
     /**
-     * @throws Throwable
+     * @throws \Throwable
      * @throws TransportExceptionInterface
      * @throws \Symfony\Component\Mailer\Exception\TransportExceptionInterface
      */
@@ -35,13 +35,11 @@ class OrganizationCreationHandler
             $organization = $this->organizationFactory->create($organizationCreationRequest);
 
             $mail['subject'] = 'New organization created';
-            $mail['content'] = 'The organization "' . $organization->getName() . '" has been created successfully.';
-
+            $mail['content'] = 'The organization "'.$organization->getName().'" has been created successfully.';
         } catch (\Exception $e) {
             $mail['subject'] = 'Organization creation : an error occured';
-            $mail['content'] = 'An error occured while creating the new organization : \n' . $e->getMessage();
+            $mail['content'] = 'An error occured while creating the new organization : \n'.$e->getMessage();
             throw $e;
-
         } finally {
             if ($organizationCreationRequest->getSendConfirmationEmailAt() !== null) {
                 $symfonyMail = (new SymfonyEmail())

+ 115 - 132
src/Service/Organization/OrganizationFactory.php

@@ -28,6 +28,7 @@ use App\Repository\Organization\OrganizationRepository;
 use App\Repository\Person\PersonRepository;
 use App\Service\ApiLegacy\ApiLegacyRequestService;
 use App\Service\Dolibarr\DolibarrApiService;
+use App\Service\Organization\Utils as OrganizationUtils;
 use App\Service\Typo3\BindFileService;
 use App\Service\Typo3\SubdomainService;
 use App\Service\Typo3\Typo3Service;
@@ -44,8 +45,6 @@ use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
 use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
 use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
 use Symfony\Contracts\Service\Attribute\Required;
-use Throwable;
-use App\Service\Organization\Utils as OrganizationUtils;
 
 class OrganizationFactory
 {
@@ -54,17 +53,17 @@ class OrganizationFactory
     protected PhoneNumberUtil $phoneNumberUtil;
 
     public function __construct(
-        private readonly SubdomainService                     $subdomainService,
-        private readonly OrganizationRepository               $organizationRepository,
-        private readonly CountryRepository                    $countryRepository,
-        private readonly OrganizationUtils                    $organizationUtils,
-        private readonly Typo3Service                         $typo3Service,
-        private readonly DolibarrApiService                   $dolibarrApiService,
-        private readonly EntityManagerInterface               $entityManager,
-        private readonly PersonRepository                     $personRepository,
-        private readonly BindFileService                      $bindFileService,
+        private readonly SubdomainService $subdomainService,
+        private readonly OrganizationRepository $organizationRepository,
+        private readonly CountryRepository $countryRepository,
+        private readonly OrganizationUtils $organizationUtils,
+        private readonly Typo3Service $typo3Service,
+        private readonly DolibarrApiService $dolibarrApiService,
+        private readonly EntityManagerInterface $entityManager,
+        private readonly PersonRepository $personRepository,
+        private readonly BindFileService $bindFileService,
         private readonly OrganizationIdentificationRepository $organizationIdentificationRepository,
-        private readonly ApiLegacyRequestService              $apiLegacyRequestService
+        private readonly ApiLegacyRequestService $apiLegacyRequestService,
     ) {
         $this->phoneNumberUtil = PhoneNumberUtil::getInstance();
     }
@@ -77,17 +76,15 @@ class OrganizationFactory
     }
 
     /**
-     * Créé une nouvelle organisation à partir des données contenues dans une OrganizationCreationRequest
+     * Créé une nouvelle organisation à partir des données contenues dans une OrganizationCreationRequest.
      *
-     * @param OrganizationCreationRequest $organizationCreationRequest
-     * @return Organization
      * @throws TransportExceptionInterface
-     * @throws Throwable
+     * @throws \Throwable
      */
     public function create(OrganizationCreationRequest $organizationCreationRequest): Organization
     {
         $this->logger->info(
-            "Start the creation of a new organization named '" . $organizationCreationRequest->getName() . "'"
+            "Start the creation of a new organization named '".$organizationCreationRequest->getName()."'"
         );
 
         $this->entityManager->beginTransaction();
@@ -98,11 +95,11 @@ class OrganizationFactory
 
             // On vérifie la validité et la disponibilité du sous domaine
             $this->validateSubdomain($organizationCreationRequest->getSubdomain());
-            $this->logger->info("Subdomain is valid and available : '" . $organizationCreationRequest->getSubdomain() . "'");
+            $this->logger->info("Subdomain is valid and available : '".$organizationCreationRequest->getSubdomain()."'");
 
             // On construit l'organisation et ses relations
             $organization = $this->makeOrganizationWithRelations($organizationCreationRequest);
-            $this->logger->info("Organization created with all its relations");
+            $this->logger->info('Organization created with all its relations');
 
             // On persiste et on commit, les objets liés seront persistés en cascade
             $this->entityManager->persist($organization);
@@ -110,12 +107,11 @@ class OrganizationFactory
             $this->entityManager->flush();
 
             $this->entityManager->commit();
-            $this->logger->debug(" - New entities committed in DB");
-
-            $this->logger->info("Organization persisted in the DB");
+            $this->logger->debug(' - New entities committed in DB');
 
+            $this->logger->info('Organization persisted in the DB');
         } catch (\Throwable $e) {
-            $this->logger->critical("An error happened, operation cancelled\n" . $e);
+            $this->logger->critical("An error happened, operation cancelled\n".$e);
             $this->entityManager->rollback();
             throw $e;
         }
@@ -128,9 +124,9 @@ class OrganizationFactory
                 $organization,
                 $organizationCreationRequest->isClient()
             );
-            $this->logger->info("New dolibarr structure created (uid : " . $dolibarrId . ")");
+            $this->logger->info('New dolibarr structure created (uid : '.$dolibarrId.')');
         } catch (\Throwable $e) {
-            $this->logger->critical("An error happened while creating the dolibarr society, please proceed manually.");
+            $this->logger->critical('An error happened while creating the dolibarr society, please proceed manually.');
             $this->logger->debug($e);
             $withError = true;
         }
@@ -138,9 +134,9 @@ class OrganizationFactory
         // Register the subdomain into the BindFile (takes up to 5min to take effect)
         try {
             $this->bindFileService->registerSubdomain($organizationCreationRequest->getSubdomain());
-            $this->logger->info("Subdomain registered");
+            $this->logger->info('Subdomain registered');
         } catch (\Throwable $e) {
-            $this->logger->critical("An error happened while updating the bind file, please proceed manually.");
+            $this->logger->critical('An error happened while updating the bind file, please proceed manually.');
             $this->logger->debug($e);
             $withError = true;
         }
@@ -148,29 +144,29 @@ class OrganizationFactory
         if ($organizationCreationRequest->getCreateWebsite()) {
             try {
                 $rootUid = $this->createTypo3Website($organization);
-                $this->logger->info("Typo3 website created (root uid: " . $rootUid . ")");
+                $this->logger->info('Typo3 website created (root uid: '.$rootUid.')');
             } catch (\Throwable $e) {
-                $this->logger->critical("An error happened while creating the typo3 website, please proceed manually.");
+                $this->logger->critical('An error happened while creating the typo3 website, please proceed manually.');
                 $this->logger->debug($e);
                 $withError = true;
             }
         } else {
-            $this->logger->warning("Typo3 website creation was not required");
+            $this->logger->warning('Typo3 website creation was not required');
         }
 
         // Création de l'organisation dans la base adminassos (géré par la V1)
         try {
             $this->updateAdminassosDb($organization);
-            $this->logger->info("Adminassos db updated");
+            $this->logger->info('Adminassos db updated');
         } catch (\Throwable $e) {
-            $this->logger->critical("An error happened while updating the adminassos db, please proceed manually.");
+            $this->logger->critical('An error happened while updating the adminassos db, please proceed manually.');
             $this->logger->debug($e);
             $withError = true;
         }
 
         if ($withError) {
             $organizationCreationRequest->setStatus(OrganizationCreationRequest::STATUS_OK_WITH_ERRORS);
-            $this->logger->warning("-- Operation ended with errors, check the logs for more information --");
+            $this->logger->warning('-- Operation ended with errors, check the logs for more information --');
         } else {
             $organizationCreationRequest->setStatus(OrganizationCreationRequest::STATUS_OK);
         }
@@ -179,43 +175,35 @@ class OrganizationFactory
     }
 
     /**
-     * Lève une exception si cette organisation existe déjà
-     *
-     * @param OrganizationCreationRequest $organizationCreationRequest
+     * Lève une exception si cette organisation existe déjà.
      */
     protected function interruptIfOrganizationExists(OrganizationCreationRequest $organizationCreationRequest): void
     {
         if (
-            $organizationCreationRequest->getSiretNumber() &&
-            $this->organizationIdentificationRepository->findOneBy(
+            $organizationCreationRequest->getSiretNumber()
+            && $this->organizationIdentificationRepository->findOneBy(
                 ['siretNumber' => $organizationCreationRequest->getSiretNumber()]
             )
         ) {
-            throw new \RuntimeException(
-                "This siret number is already registered : '" . $organizationCreationRequest->getSiretNumber() . "'"
-            );
+            throw new \RuntimeException("This siret number is already registered : '".$organizationCreationRequest->getSiretNumber()."'");
         }
 
         if (
-            $organizationCreationRequest->getWaldecNumber() &&
-            $this->organizationIdentificationRepository->findOneBy(
+            $organizationCreationRequest->getWaldecNumber()
+            && $this->organizationIdentificationRepository->findOneBy(
                 ['waldecNumber' => $organizationCreationRequest->getWaldecNumber()]
             )
         ) {
-            throw new \RuntimeException(
-                "This RNA identifier (waldec number) is already registered : '" . $organizationCreationRequest->getWaldecNumber() . "'"
-            );
+            throw new \RuntimeException("This RNA identifier (waldec number) is already registered : '".$organizationCreationRequest->getWaldecNumber()."'");
         }
 
         if (
-            $organizationCreationRequest->getIdentifier() &&
-            $this->organizationIdentificationRepository->findOneBy(
+            $organizationCreationRequest->getIdentifier()
+            && $this->organizationIdentificationRepository->findOneBy(
                 ['identifier' => $organizationCreationRequest->getIdentifier()]
             )
         ) {
-            throw new \RuntimeException(
-                "This CMF identifier is already registered : '" . $organizationCreationRequest->getIdentifier() . "'"
-            );
+            throw new \RuntimeException("This CMF identifier is already registered : '".$organizationCreationRequest->getIdentifier()."'");
         }
 
         $normalizedName = $this->normalizeIdentificationField($organizationCreationRequest->getName());
@@ -225,16 +213,13 @@ class OrganizationFactory
                 ['normalizedName' => $normalizedName, 'addressCity' => $organizationCreationRequest->getCity()]
             )
         ) {
-            throw new \RuntimeException(
-                "An organization named '" . $organizationCreationRequest->getName() .
-                "' already exists in " . $organizationCreationRequest->getCity()
-            );
+            throw new \RuntimeException("An organization named '".$organizationCreationRequest->getName()."' already exists in ".$organizationCreationRequest->getCity());
         }
 
         $address = $this->normalizeIdentificationField(implode(' ', [
             $organizationCreationRequest->getStreetAddress1(),
             $organizationCreationRequest->getStreetAddress2(),
-            $organizationCreationRequest->getStreetAddress3()
+            $organizationCreationRequest->getStreetAddress3(),
         ]));
 
         if (
@@ -242,35 +227,31 @@ class OrganizationFactory
                 [
                     'normalizedAddress' => $address,
                     'addressCity' => $organizationCreationRequest->getCity(),
-                    'postalCode' => $organizationCreationRequest->getPostalCode()
+                    'postalCode' => $organizationCreationRequest->getPostalCode(),
                 ]
             )
         ) {
-            throw new \RuntimeException(
-                'An organization already exists at this address.'
-            );
+            throw new \RuntimeException('An organization already exists at this address.');
         }
     }
 
     /**
-     * Vérifie la disponibilité et la validité d'un sous domaine
+     * Vérifie la disponibilité et la validité d'un sous domaine.
      *
-     * @param string $subdomainValue
-     * @return void
      * @throws \Exception
      */
     protected function validateSubdomain(string $subdomainValue): void
     {
         if (!$this->subdomainService->isValidSubdomain($subdomainValue)) {
-            throw new \RuntimeException("Not a valid subdomain : " . $subdomainValue);
+            throw new \RuntimeException('Not a valid subdomain : '.$subdomainValue);
         }
 
         if ($this->subdomainService->isReservedSubdomain($subdomainValue)) {
-            throw new \RuntimeException("This subdomain is not available : " . $subdomainValue);
+            throw new \RuntimeException('This subdomain is not available : '.$subdomainValue);
         }
 
         if ($this->subdomainService->isRegistered($subdomainValue)) {
-            throw new \RuntimeException("This subdomain is already registered : " . $subdomainValue);
+            throw new \RuntimeException('This subdomain is already registered : '.$subdomainValue);
         }
     }
 
@@ -278,53 +259,50 @@ class OrganizationFactory
      * Créé une nouvelle instance d'organisation, et toutes les instances liées (paramètres, contact, adresses, ...),
      * selon le contenu de la requête de création.
      *
-     * @param OrganizationCreationRequest $organizationCreationRequest
-     * @return Organization
-     * @throws Throwable
+     * @throws \Throwable
      */
     protected function makeOrganizationWithRelations(
-        OrganizationCreationRequest $organizationCreationRequest
-    ): Organization
-    {
+        OrganizationCreationRequest $organizationCreationRequest,
+    ): Organization {
         // Création de l'organisation
         $organization = $this->makeOrganization($organizationCreationRequest);
-        $this->logger->debug(" - Organization created");
+        $this->logger->debug(' - Organization created');
 
         // Création des Parameters
         $parameters = $this->makeParameters($organizationCreationRequest);
         $organization->setParameters($parameters);
-        $this->logger->debug(" - Parameters created");
+        $this->logger->debug(' - Parameters created');
 
         // Création des Settings
         $settings = $this->makeSettings($organizationCreationRequest);
         $organization->setSettings($settings);
-        $this->logger->debug(" - Settings created");
+        $this->logger->debug(' - Settings created');
 
         // Création de l'adresse postale
         $organizationAddressPostal = $this->makePostalAddress($organizationCreationRequest);
         $organization->addOrganizationAddressPostal($organizationAddressPostal);
-        $this->logger->debug(" - OrganizationAddressPostal created");
+        $this->logger->debug(' - OrganizationAddressPostal created');
 
         // Création du point de contact
         $contactPoint = $this->makeContactPoint($organizationCreationRequest);
         $organization->addContactPoint($contactPoint);
-        $this->logger->debug(" - ContactPoint created");
+        $this->logger->debug(' - ContactPoint created');
 
         // Rattachement au réseau
         $networkOrganization = $this->makeNetworkOrganization($organizationCreationRequest);
         $organization->addNetworkOrganization($networkOrganization);
-        $this->logger->debug(" - NetworkOrganization created");
+        $this->logger->debug(' - NetworkOrganization created');
 
         // Créé l'admin
         $adminAccess = $this->makeAdminAccess($organizationCreationRequest);
         $organization->addAccess($adminAccess);
-        $this->logger->debug(" - Admin access created");
+        $this->logger->debug(' - Admin access created');
 
         // Création des cycles
         foreach ($this->makeCycles() as $cycle) {
             $organization->addCycle($cycle);
         }
-        $this->logger->debug(" - Cycles created");
+        $this->logger->debug(' - Cycles created');
 
         // Création du président (si renseigné)
         $presidentCreationRequest = $organizationCreationRequest->getPresident();
@@ -338,7 +316,7 @@ class OrganizationFactory
             $presidentAccess->setCreatedBy($organizationCreationRequest->getAuthorId());
 
             $organization->addAccess($presidentAccess);
-            $this->logger->debug(" - President access created");
+            $this->logger->debug(' - President access created');
         }
 
         // Création du directeur (si renseigné)
@@ -353,7 +331,7 @@ class OrganizationFactory
             $directorAccess->setCreatedBy($organizationCreationRequest->getAuthorId());
 
             $organization->addAccess($directorAccess);
-            $this->logger->debug(" - Director access created");
+            $this->logger->debug(' - Director access created');
         }
 
         // Création du sous-domaine
@@ -363,18 +341,15 @@ class OrganizationFactory
         // <--- Pour la rétrocompatibilité avec la v1 ; pourra être supprimé lorsque la migration sera achevée
         $parameters = $organization->getParameters();
         $parameters->setSubDomain($organizationCreationRequest->getSubdomain());
-        $parameters->setOtherWebsite('https://' . $organizationCreationRequest->getSubdomain() . '.opentalent.fr');
+        $parameters->setOtherWebsite('https://'.$organizationCreationRequest->getSubdomain().'.opentalent.fr');
         // --->
-        $this->logger->debug(" - Subdomain created");
+        $this->logger->debug(' - Subdomain created');
 
         return $organization;
     }
 
     /**
-     * Créé une nouvelle instance d'organisation
-     *
-     * @param OrganizationCreationRequest $organizationCreationRequest
-     * @return Organization
+     * Créé une nouvelle instance d'organisation.
      */
     protected function makeOrganization(OrganizationCreationRequest $organizationCreationRequest): Organization
     {
@@ -387,28 +362,32 @@ class OrganizationFactory
         $organization->setCreationDate($organizationCreationRequest->getCreationDate());
         $organization->setCreateDate($organizationCreationRequest->getCreationDate());
         $organization->setCreatedBy($organizationCreationRequest->getAuthorId());
+
         return $organization;
     }
 
     /**
-     * Create a new Parameters object from the data in an OrganizationCreationRequest
+     * Create a new Parameters object from the data in an OrganizationCreationRequest.
      *
      * @param OrganizationCreationRequest $organizationCreationRequest The organization creation request
+     *
      * @return Parameters The created Parameters object
-     * @throws Throwable If there is an error
+     *
+     * @throws \Throwable If there is an error
      */
     protected function makeParameters(OrganizationCreationRequest $organizationCreationRequest): Parameters
     {
         $parameters = new Parameters();
+
         return $parameters;
     }
 
     /**
      * Creates a new instance of the Settings class based on the given OrganizationCreationRequest object.
      *
-     * @param OrganizationCreationRequest $organizationCreationRequest The OrganizationCreationRequest object containing the required data.
+     * @param OrganizationCreationRequest $organizationCreationRequest the OrganizationCreationRequest object containing the required data
      *
-     * @return Settings The newly created instance of the Settings class.
+     * @return Settings the newly created instance of the Settings class
      */
     protected function makeSettings(OrganizationCreationRequest $organizationCreationRequest): Settings
     {
@@ -422,21 +401,22 @@ class OrganizationFactory
 
         $settings->setCreateDate($organizationCreationRequest->getCreationDate());
         $settings->setCreatedBy($organizationCreationRequest->getAuthorId());
+
         return $settings;
     }
 
     /**
      * Creates a new instance of the OrganizationAddressPostal class based on the given OrganizationCreationRequest object.
      *
-     * @param OrganizationCreationRequest $organizationCreationRequest The OrganizationCreationRequest object containing the required data.
+     * @param OrganizationCreationRequest $organizationCreationRequest the OrganizationCreationRequest object containing the required data
      *
-     * @return OrganizationAddressPostal The newly created instance of the OrganizationAddressPostal class.
+     * @return OrganizationAddressPostal the newly created instance of the OrganizationAddressPostal class
      */
     protected function makePostalAddress(OrganizationCreationRequest $organizationCreationRequest): OrganizationAddressPostal
     {
         $country = $this->countryRepository->find($organizationCreationRequest->getCountryId());
         if (!$country) {
-            throw new \RuntimeException('No country found for id ' . $organizationCreationRequest->getCountryId());
+            throw new \RuntimeException('No country found for id '.$organizationCreationRequest->getCountryId());
         }
 
         $addressPostal = new AddressPostal();
@@ -461,15 +441,16 @@ class OrganizationFactory
     /**
      * Creates a new instance of the ContactPoint class based on the given OrganizationCreationRequest object.
      *
-     * @param OrganizationCreationRequest $organizationCreationRequest The OrganizationCreationRequest object containing the required data.
+     * @param OrganizationCreationRequest $organizationCreationRequest the OrganizationCreationRequest object containing the required data
+     *
+     * @return ContactPoint the newly created instance of the ContactPoint class
      *
-     * @return ContactPoint The newly created instance of the ContactPoint class.
      * @throws NumberParseException
      */
     protected function makeContactPoint(OrganizationCreationRequest $organizationCreationRequest): ContactPoint
     {
         if (!$this->phoneNumberUtil->isPossibleNumber($organizationCreationRequest->getPhoneNumber())) {
-            throw new \RuntimeException("Phone number is invalid or missing");
+            throw new \RuntimeException('Phone number is invalid or missing');
         }
         $phoneNumber = $this->phoneNumberUtil->parse($organizationCreationRequest->getPhoneNumber());
 
@@ -486,29 +467,26 @@ class OrganizationFactory
     /**
      * Creates a new instance of the NetworkOrganization class based on the given OrganizationCreationRequest object.
      *
-     * @param OrganizationCreationRequest $organizationCreationRequest The OrganizationCreationRequest object containing the required data.
+     * @param OrganizationCreationRequest $organizationCreationRequest the OrganizationCreationRequest object containing the required data
      *
-     * @return NetworkOrganization The newly created instance of the NetworkOrganization class.
+     * @return NetworkOrganization the newly created instance of the NetworkOrganization class
      *
-     * @throws \RuntimeException|\Exception if no parent organization is found for the given parent ID or if no network is found for the given network ID.
+     * @throws \RuntimeException|\Exception if no parent organization is found for the given parent ID or if no network is found for the given network ID
      */
     protected function makeNetworkOrganization(OrganizationCreationRequest $organizationCreationRequest): NetworkOrganization
     {
         $parent = $this->organizationRepository->find($organizationCreationRequest->getParentId());
         if (!$parent) {
-            throw new \RuntimeException('No parent organization found for id ' . $organizationCreationRequest->getParentId());
+            throw new \RuntimeException('No parent organization found for id '.$organizationCreationRequest->getParentId());
         }
 
         if ($parent->getSettings()->getProduct() !== SettingsProductEnum::MANAGER) {
-            throw new \RuntimeException(
-                "Parent organization must have the product 'manager' (actual product: '" .
-                $parent->getSettings()->getProduct()->value . "')"
-            );
+            throw new \RuntimeException("Parent organization must have the product 'manager' (actual product: '".$parent->getSettings()->getProduct()->value."')");
         }
 
         $networkOrganization = $this->organizationUtils->getActiveNetworkOrganization($parent);
         if (!$networkOrganization) {
-            throw new \RuntimeException('No network found for parent ' . $organizationCreationRequest->getParentId());
+            throw new \RuntimeException('No network found for parent '.$organizationCreationRequest->getParentId());
         }
 
         $network = $networkOrganization->getNetwork();
@@ -516,7 +494,7 @@ class OrganizationFactory
         // Si réseau CMF, on vérifie que le matricule est valide
         if ($network->getId() === NetworkEnum::CMF->value) {
             if (!preg_match("/FR\d{12}/", $organizationCreationRequest->getIdentifier())) {
-                throw new \RuntimeException("CMF identifier is missing or invalid.");
+                throw new \RuntimeException('CMF identifier is missing or invalid.');
             }
         }
 
@@ -533,14 +511,14 @@ class OrganizationFactory
     /**
      * Creates a new instance of the Access class with admin access based on the given OrganizationCreationRequest object.
      *
-     * @param OrganizationCreationRequest $organizationCreationRequest The OrganizationCreationRequest object containing the required data.
+     * @param OrganizationCreationRequest $organizationCreationRequest the OrganizationCreationRequest object containing the required data
      *
-     * @return Access The newly created instance of the Access class with admin access.
+     * @return Access the newly created instance of the Access class with admin access
      */
     protected function makeAdminAccess(OrganizationCreationRequest $organizationCreationRequest): Access
     {
         $admin = new Person();
-        $admin->setUsername('admin' . strtolower($organizationCreationRequest->getSubdomain()));
+        $admin->setUsername('admin'.strtolower($organizationCreationRequest->getSubdomain()));
         $randomString = ByteString::fromRandom(32)->toString();
         $admin->setPassword($randomString);
 
@@ -556,7 +534,7 @@ class OrganizationFactory
     /**
      * Creates an array of Cycle objects based on a predefined set of data.
      *
-     * @return Cycle[] An array of Cycle objects.
+     * @return Cycle[] an array of Cycle objects
      */
     protected function makeCycles(): array
     {
@@ -586,16 +564,17 @@ class OrganizationFactory
     /**
      * Creates an Access object based on the given OrganizationMemberCreationRequest.
      *
-     * @param int|OrganizationMemberCreationRequest $creationRequestData The request object containing the
+     * @param int|OrganizationMemberCreationRequest $creationRequestData the request object containing the
      *                                                                   necessary data for creating a Person object,
-     *                                                                   or the id of an existing one.
-     * @return Access The created Access object.
+     *                                                                   or the id of an existing one
+     *
+     * @return Access the created Access object
+     *
      * @throws NumberParseException
      */
     protected function makeAccess(
-        int | OrganizationMemberCreationRequest $creationRequestData
-    ): Access
-    {
+        int|OrganizationMemberCreationRequest $creationRequestData,
+    ): Access {
         if (is_int($creationRequestData)) {
             $person = $this->personRepository->find($creationRequestData);
         } else {
@@ -630,10 +609,11 @@ class OrganizationFactory
     /**
      * Creates a PersonAddressPostal object based on the given OrganizationMemberCreationRequest.
      *
-     * @param OrganizationMemberCreationRequest $organizationMemberCreationRequest The request object containing the
+     * @param OrganizationMemberCreationRequest $organizationMemberCreationRequest the request object containing the
      *                                                                             necessary data for creating a
-     *                                                                             PersonAddressPostal object.
-     * @return PersonAddressPostal The created PersonAddressPostal object.
+     *                                                                             PersonAddressPostal object
+     *
+     * @return PersonAddressPostal the created PersonAddressPostal object
      */
     protected function makePersonPostalAddress(OrganizationMemberCreationRequest $organizationMemberCreationRequest): PersonAddressPostal
     {
@@ -661,9 +641,10 @@ class OrganizationFactory
     /**
      * Creates a new instance of the ContactPoint class based on the given OrganizationCreationRequest object.
      *
-     * @param OrganizationMemberCreationRequest $organizationMemberCreationRequest The OrganizationMemberCreationRequest object containing the required data.
+     * @param OrganizationMemberCreationRequest $organizationMemberCreationRequest the OrganizationMemberCreationRequest object containing the required data
+     *
+     * @return ContactPoint the newly created instance of the ContactPoint class
      *
-     * @return ContactPoint The newly created instance of the ContactPoint class.
      * @throws NumberParseException
      */
     protected function makePersonContactPoint(OrganizationMemberCreationRequest $organizationMemberCreationRequest): ContactPoint
@@ -683,6 +664,7 @@ class OrganizationFactory
 
         $contactPoint->setCreateDate($organizationMemberCreationRequest->getCreationDate());
         $contactPoint->setCreatedBy($organizationMemberCreationRequest->getAuthorId());
+
         return $contactPoint;
     }
 
@@ -691,18 +673,20 @@ class OrganizationFactory
         $subdomain = new Subdomain();
         $subdomain->setSubdomain($organizationCreationRequest->getSubdomain());
         $subdomain->setActive(true);
+
         return $subdomain;
     }
 
     /**
-     * Créé le site Typo3 et retourne l'id de la page racine du site nouvellement créé, ou null en cas d'erreur
+     * Créé le site Typo3 et retourne l'id de la page racine du site nouvellement créé, ou null en cas d'erreur.
      *
      * @throws RedirectionExceptionInterface
      * @throws ClientExceptionInterface
      * @throws TransportExceptionInterface
      * @throws ServerExceptionInterface
      */
-    protected function createTypo3Website(Organization $organization): ?int {
+    protected function createTypo3Website(Organization $organization): ?int
+    {
         $response = $this->typo3Service->createSite($organization->getId());
         $content = json_decode($response->getContent(), true);
         $rootPageUid = $content['root_uid'];
@@ -726,27 +710,26 @@ class OrganizationFactory
     {
         $response = $this->apiLegacyRequestService->post(
             '/_internal/secure/organization/creation-event',
-            [ 'organizationId' => $organization->getId() ]
+            ['organizationId' => $organization->getId()]
         );
 
         if ($response->getStatusCode() !== Response::HTTP_OK) {
-            throw new \RuntimeException('An error happened while updating the adminassos database: ' . $response->getContent());
+            throw new \RuntimeException('An error happened while updating the adminassos database: '.$response->getContent());
         }
     }
 
     /**
-     * Normalise la chaine comme sont normalisées les champs de l'entité OrganizationIdentification
+     * Normalise la chaine comme sont normalisées les champs de l'entité OrganizationIdentification.
      *
      * @øee sql/schema-extensions/003-view_organization_identification.sql
-     *
-     * @param string $value
-     * @return string
      */
-    protected function normalizeIdentificationField(string $value): string {
+    protected function normalizeIdentificationField(string $value): string
+    {
         $value = strtolower(trim($value));
         $value = preg_replace('/[éèê]/u', 'e', $value);
         $value = preg_replace('/[à]/u', 'a', $value);
         $value = preg_replace('/[ç]/u', 'c', $value);
+
         return preg_replace('/[^a-z0-9]+/u', '+', $value);
     }
 }

+ 5 - 3
src/State/Processor/Organization/OrganizationCreationRequestProcessor.php

@@ -22,12 +22,13 @@ class OrganizationCreationRequestProcessor implements ProcessorInterface
         private readonly MessageBusInterface $messageBus,
         private readonly OrganizationFactory $organizationFactory,
         private Security $security,
-    ) {}
+    ) {
+    }
 
     /**
      * @param OrganizationCreationRequest $organizationCreationRequest
-     * @param mixed[]       $uriVariables
-     * @param mixed[]       $context
+     * @param mixed[]                     $uriVariables
+     * @param mixed[]                     $context
      *
      * @throws \Exception
      */
@@ -52,6 +53,7 @@ class OrganizationCreationRequestProcessor implements ProcessorInterface
             // For testing purposes only
             $this->organizationFactory->create($organizationCreationRequest);
         }
+
         return $organizationCreationRequest;
     }
 }