瀏覽代碼

minor refactoring on HelloAssoService

Olivier Massot 2 月之前
父節點
當前提交
6a5d7bcc0d
共有 1 個文件被更改,包括 4 次插入13 次删除
  1. 4 13
      src/Service/HelloAsso/HelloAssoService.php

+ 4 - 13
src/Service/HelloAsso/HelloAssoService.php

@@ -257,10 +257,6 @@ class HelloAssoService extends ApiRequestService
     {
         $helloAssoEntity = $this->getHelloAssoEntityFor($organizationId);
 
-        if (!$helloAssoEntity->getOrganizationSlug() || !$helloAssoEntity->getToken()) {
-            throw new \RuntimeException('HelloAsso entity incomplete');
-        }
-
         $formType = 'Event';
 
         $data = $this->getResource(
@@ -278,14 +274,6 @@ class HelloAssoService extends ApiRequestService
             throw new \RuntimeException('Event not found');
         }
 
-        $organizationId = $event->getOrganization()->getId();
-
-        $helloAssoEntity = $this->getHelloAssoEntityFor($organizationId);
-
-        if (!$helloAssoEntity->getOrganizationSlug() || !$helloAssoEntity->getToken()) {
-            throw new \RuntimeException('HelloAsso entity incomplete');
-        }
-
         $helloAssoFormSlug = $event->getHelloAssoSlug();
         if (!$helloAssoFormSlug) {
             throw new \RuntimeException('HelloAsso form slug not found');
@@ -294,7 +282,7 @@ class HelloAssoService extends ApiRequestService
         return $this->getHelloAssoEventForm($organizationId, $helloAssoFormSlug);
     }
 
-    protected function getHelloAssoEntityFor(int $organizationId): HelloAsso
+    protected function getHelloAssoEntityFor(int $organizationId, bool $shallHaveToken = true): HelloAsso
     {
         $organization = $this->organizationRepository->find($organizationId);
         if (!$organization) {
@@ -304,6 +292,9 @@ class HelloAssoService extends ApiRequestService
         if (!$helloAssoEntity) {
             throw new \RuntimeException('HelloAsso entity not found');
         }
+        if ($shallHaveToken && (!$helloAssoEntity->getOrganizationSlug() || !$helloAssoEntity->getToken())) {
+            throw new \RuntimeException('HelloAsso entity incomplete');
+        }
         return $helloAssoEntity;
     }