Completed
Pull Request — master (#1218)
by
unknown
52s
created
SWP/Bundle/ElasticSearchBundle/Controller/Api/PackageSearchController.php 2 patches
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -32,27 +32,27 @@  discard block
 block discarded – undo
32 32
 
33 33
 class PackageSearchController extends AbstractController {
34 34
 
35
-  private PaginatorInterface $paginator;
36
-  private EventDispatcherInterface $eventDispatcher;
37
-  private CachedTenantContext $cachedTenantContext;
35
+    private PaginatorInterface $paginator;
36
+    private EventDispatcherInterface $eventDispatcher;
37
+    private CachedTenantContext $cachedTenantContext;
38 38
 
39
-  /**
40
-   * @param PaginatorInterface $paginator
41
-   * @param EventDispatcherInterface $eventDispatcher
42
-   * @param CachedTenantContext $cachedTenantContext
43
-   */
44
-  public function __construct(PaginatorInterface  $paginator, EventDispatcherInterface $eventDispatcher,
45
-                              CachedTenantContext $cachedTenantContext) {
39
+    /**
40
+     * @param PaginatorInterface $paginator
41
+     * @param EventDispatcherInterface $eventDispatcher
42
+     * @param CachedTenantContext $cachedTenantContext
43
+     */
44
+    public function __construct(PaginatorInterface  $paginator, EventDispatcherInterface $eventDispatcher,
45
+                                CachedTenantContext $cachedTenantContext) {
46 46
     $this->paginator = $paginator;
47 47
     $this->eventDispatcher = $eventDispatcher;
48 48
     $this->cachedTenantContext = $cachedTenantContext;
49
-  }
49
+    }
50 50
 
51 51
 
52
-  /**
53
-   * @Route("/api/{version}/packages/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_list_packages")
54
-   */
55
-  public function searchAction(Request $request, RepositoryManagerInterface $repositoryManager) {
52
+    /**
53
+     * @Route("/api/{version}/packages/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_list_packages")
54
+     */
55
+    public function searchAction(Request $request, RepositoryManagerInterface $repositoryManager) {
56 56
     $this->eventDispatcher->dispatch( new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE);
57 57
     $currentTenant = $this->cachedTenantContext->getTenant();
58 58
 
@@ -106,5 +106,5 @@  discard block
 block discarded – undo
106 106
     );
107 107
 
108 108
     return new ResourcesListResponse($pagination, $responseContext);
109
-  }
109
+    }
110 110
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
    * @Route("/api/{version}/packages/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_list_packages")
54 54
    */
55 55
   public function searchAction(Request $request, RepositoryManagerInterface $repositoryManager) {
56
-    $this->eventDispatcher->dispatch( new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE);
56
+    $this->eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE);
57 57
     $currentTenant = $this->cachedTenantContext->getTenant();
58 58
 
59 59
     $criteria = Criteria::fromQueryParameters(
@@ -62,14 +62,14 @@  discard block
 block discarded – undo
62 62
             'page' => $request->query->get('page'),
63 63
             'sort' => $request->query->get('sorting'),
64 64
             'limit' => $request->query->get('limit', 10),
65
-            'authors' => array_filter((array)$request->query->get('author', [])),
65
+            'authors' => array_filter((array) $request->query->get('author', [])),
66 66
             'publishedBefore' => $request->query->get('published_before'),
67 67
             'publishedAfter' => $request->query->get('published_after'),
68 68
             'organization' => $currentTenant->getOrganization()->getId(),
69
-            'sources' => array_filter((array)$request->query->get('source', [])),
70
-            'tenants' => array_filter((array)$request->query->get('tenant', [])),
71
-            'routes' => array_filter((array)$request->query->get('route', [])),
72
-            'statuses' => array_filter((array)$request->query->get('status', [])),
69
+            'sources' => array_filter((array) $request->query->get('source', [])),
70
+            'tenants' => array_filter((array) $request->query->get('tenant', [])),
71
+            'routes' => array_filter((array) $request->query->get('route', [])),
72
+            'statuses' => array_filter((array) $request->query->get('status', [])),
73 73
             'language' => $request->query->get('language', ''),
74 74
         ]
75 75
     );
Please login to merge, or discard this patch.
SWP/Bundle/ElasticSearchBundle/Controller/Api/AuthorSearchController.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -26,27 +26,27 @@  discard block
 block discarded – undo
26 26
 use Symfony\Component\Routing\Annotation\Route;
27 27
 
28 28
 class AuthorSearchController extends AbstractController {
29
-  private RepositoryManagerInterface $repositoryManager;
30
-  private PaginatorInterface $paginator;
31
-  private string $authorClassName;
29
+    private RepositoryManagerInterface $repositoryManager;
30
+    private PaginatorInterface $paginator;
31
+    private string $authorClassName;
32 32
 
33
-  /**
34
-   * @param RepositoryManagerInterface $repositoryManager
35
-   * @param PaginatorInterface $paginator
36
-   * @param string $authorClassName
37
-   */
38
-  public function __construct(RepositoryManagerInterface $repositoryManager, PaginatorInterface $paginator,
39
-                              string                     $authorClassName) {
33
+    /**
34
+     * @param RepositoryManagerInterface $repositoryManager
35
+     * @param PaginatorInterface $paginator
36
+     * @param string $authorClassName
37
+     */
38
+    public function __construct(RepositoryManagerInterface $repositoryManager, PaginatorInterface $paginator,
39
+                                string                     $authorClassName) {
40 40
     $this->repositoryManager = $repositoryManager;
41 41
     $this->paginator = $paginator;
42 42
     $this->authorClassName = $authorClassName;
43
-  }
43
+    }
44 44
 
45 45
 
46
-  /**
47
-   * @Route("/api/{version}/authors/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_list_authors")
48
-   */
49
-  public function searchAction(Request $request): ResourcesListResponse {
46
+    /**
47
+     * @Route("/api/{version}/authors/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_list_authors")
48
+     */
49
+    public function searchAction(Request $request): ResourcesListResponse {
50 50
     $criteria = Criteria::fromQueryParameters(
51 51
         $request->query->get('term', ''),
52 52
         [
@@ -87,5 +87,5 @@  discard block
 block discarded – undo
87 87
     );
88 88
 
89 89
     return new ResourcesListResponse($pagination, $responseContext);
90
-  }
90
+    }
91 91
 }
Please login to merge, or discard this patch.
src/SWP/Bundle/CoreBundle/EventListener/BodyListener.php 2 patches
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -28,35 +28,35 @@  discard block
 block discarded – undo
28 28
 
29 29
 class BodyListener
30 30
 {
31
-  private $decoderProvider;
32
-  private $throwExceptionOnUnsupportedContentType;
33
-  private $defaultFormat;
34
-  private $arrayNormalizer;
35
-  private $normalizeForms;
36
-
37
-  public function __construct(
38
-      DecoderProviderInterface $decoderProvider,
39
-      bool $throwExceptionOnUnsupportedContentType = false,
40
-      ArrayNormalizerInterface $arrayNormalizer = null,
41
-      bool $normalizeForms = false
42
-  ) {
31
+    private $decoderProvider;
32
+    private $throwExceptionOnUnsupportedContentType;
33
+    private $defaultFormat;
34
+    private $arrayNormalizer;
35
+    private $normalizeForms;
36
+
37
+    public function __construct(
38
+        DecoderProviderInterface $decoderProvider,
39
+        bool $throwExceptionOnUnsupportedContentType = false,
40
+        ArrayNormalizerInterface $arrayNormalizer = null,
41
+        bool $normalizeForms = false
42
+    ) {
43 43
     $this->decoderProvider = $decoderProvider;
44 44
     $this->throwExceptionOnUnsupportedContentType = $throwExceptionOnUnsupportedContentType;
45 45
     $this->arrayNormalizer = $arrayNormalizer;
46 46
     $this->normalizeForms = $normalizeForms;
47
-  }
47
+    }
48 48
 
49
-  public function setDefaultFormat(?string $defaultFormat): void
50
-  {
49
+    public function setDefaultFormat(?string $defaultFormat): void
50
+    {
51 51
     $this->defaultFormat = $defaultFormat;
52
-  }
52
+    }
53 53
 
54
-  public function onKernelRequest(RequestEvent $event): void
55
-  {
54
+    public function onKernelRequest(RequestEvent $event): void
55
+    {
56 56
     $request = $event->getRequest();
57 57
 
58 58
     if (!$request->attributes->get(FOSRestBundle::ZONE_ATTRIBUTE, true)) {
59
-      return;
59
+        return;
60 60
     }
61 61
 
62 62
     $method = $request->getMethod();
@@ -64,83 +64,83 @@  discard block
 block discarded – undo
64 64
     $normalizeRequest = $this->normalizeForms && $this->isFormRequest($request);
65 65
 
66 66
     if ($this->isDecodeable($request)) {
67
-      $format = null === $contentType
67
+        $format = null === $contentType
68 68
           ? $request->getRequestFormat()
69 69
           : $request->getFormat($contentType);
70 70
 
71
-      $format = $format ?: $this->defaultFormat;
71
+        $format = $format ?: $this->defaultFormat;
72 72
 
73
-      $content = $request->getContent();
73
+        $content = $request->getContent();
74 74
 
75
-      if (null === $format || !$this->decoderProvider->supports($format)) {
75
+        if (null === $format || !$this->decoderProvider->supports($format)) {
76 76
         if ($this->throwExceptionOnUnsupportedContentType
77 77
             && $this->isNotAnEmptyDeleteRequestWithNoSetContentType($method, $content, $contentType)
78 78
         ) {
79
-          throw new UnsupportedMediaTypeHttpException("Request body format '$format' not supported");
79
+            throw new UnsupportedMediaTypeHttpException("Request body format '$format' not supported");
80 80
         }
81 81
 
82 82
         return;
83
-      }
83
+        }
84 84
 
85
-      if (!empty($content)) {
85
+        if (!empty($content)) {
86 86
         $decoder = $this->decoderProvider->getDecoder($format);
87 87
         $data = $decoder->decode($content);
88 88
         if (is_array($data)) {
89
-          $request->request = new ParameterBag($data);
90
-          $normalizeRequest = true;
89
+            $request->request = new ParameterBag($data);
90
+            $normalizeRequest = true;
91 91
         } else {
92
-          throw new BadRequestHttpException('Invalid '.$format.' message received');
92
+            throw new BadRequestHttpException('Invalid '.$format.' message received');
93
+        }
93 94
         }
94
-      }
95 95
     }
96 96
 
97 97
     if (null !== $this->arrayNormalizer && $normalizeRequest) {
98
-      $data = $request->request->all();
98
+        $data = $request->request->all();
99 99
 
100
-      try {
100
+        try {
101 101
         $data = $this->arrayNormalizer->normalize($data);
102
-      } catch (NormalizationException $e) {
102
+        } catch (NormalizationException $e) {
103 103
         throw new BadRequestHttpException($e->getMessage());
104
-      }
104
+        }
105 105
 
106
-      $request->request = new ParameterBag($data);
106
+        $request->request = new ParameterBag($data);
107 107
 
108
-      if(!empty($request->files->all())) {
108
+        if(!empty($request->files->all())) {
109 109
         $data = $request->files->all();
110 110
 
111 111
         try {
112
-          $data = $this->arrayNormalizer->normalize($data);
112
+            $data = $this->arrayNormalizer->normalize($data);
113 113
         } catch (NormalizationException $e) {
114
-          throw new BadRequestHttpException($e->getMessage());
114
+            throw new BadRequestHttpException($e->getMessage());
115 115
         }
116 116
 
117 117
         $request->files = new ParameterBag($data);
118
-      }
118
+        }
119
+    }
119 120
     }
120
-  }
121 121
 
122
-  private function isNotAnEmptyDeleteRequestWithNoSetContentType(string $method, $content, ?string $contentType): bool
123
-  {
122
+    private function isNotAnEmptyDeleteRequestWithNoSetContentType(string $method, $content, ?string $contentType): bool
123
+    {
124 124
     return false === ('DELETE' === $method && empty($content) && empty($contentType));
125
-  }
125
+    }
126 126
 
127
-  private function isDecodeable(Request $request): bool
128
-  {
127
+    private function isDecodeable(Request $request): bool
128
+    {
129 129
     if (!in_array($request->getMethod(), ['POST', 'PUT', 'PATCH', 'DELETE'])) {
130
-      return false;
130
+        return false;
131 131
     }
132 132
 
133 133
     return !$this->isFormRequest($request);
134
-  }
134
+    }
135 135
 
136
-  private function isFormRequest(Request $request): bool
137
-  {
136
+    private function isFormRequest(Request $request): bool
137
+    {
138 138
     $contentTypeParts = explode(';', $request->headers->get('Content-Type'));
139 139
 
140 140
     if (isset($contentTypeParts[0])) {
141
-      return in_array($contentTypeParts[0], ['multipart/form-data', 'application/x-www-form-urlencoded']);
141
+        return in_array($contentTypeParts[0], ['multipart/form-data', 'application/x-www-form-urlencoded']);
142 142
     }
143 143
 
144 144
     return false;
145
-  }
145
+    }
146 146
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -105,7 +105,7 @@
 block discarded – undo
105 105
 
106 106
       $request->request = new ParameterBag($data);
107 107
 
108
-      if(!empty($request->files->all())) {
108
+      if (!empty($request->files->all())) {
109 109
         $data = $request->files->all();
110 110
 
111 111
         try {
Please login to merge, or discard this patch.
src/SWP/Bundle/CoreBundle/EventListener/SecuredContentPushListener.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@
 block discarded – undo
20 20
 use SWP\Bundle\CoreBundle\Model\OrganizationInterface;
21 21
 use SWP\Component\MultiTenancy\Context\TenantContextInterface;
22 22
 use Symfony\Component\HttpFoundation\Response;
23
-use Symfony\Component\HttpKernel\Event\RequestEvent ;
23
+use Symfony\Component\HttpKernel\Event\RequestEvent;
24 24
 
25 25
 class SecuredContentPushListener
26 26
 {
Please login to merge, or discard this patch.
src/SWP/Bundle/CoreBundle/EventListener/CurrentDeviceListener.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@
 block discarded – undo
15 15
 namespace SWP\Bundle\CoreBundle\EventListener;
16 16
 
17 17
 use SWP\Bundle\CoreBundle\Detection\DeviceDetectionInterface;
18
-use Symfony\Component\HttpKernel\Event\RequestEvent ;
18
+use Symfony\Component\HttpKernel\Event\RequestEvent;
19 19
 use Symfony\Component\HttpKernel\HttpKernelInterface;
20 20
 
21 21
 class CurrentDeviceListener
Please login to merge, or discard this patch.
src/SWP/Bundle/CoreBundle/Controller/SubscriptionController.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -28,24 +28,24 @@  discard block
 block discarded – undo
28 28
 
29 29
 class SubscriptionController extends Controller {
30 30
 
31
-  private SubscriptionsProviderInterface $subscriptionsProvider;
32
-  private RepositoryInterface $userRepository;
33
-
34
-  /**
35
-   * @param SubscriptionsProviderInterface $subscriptionsProvider
36
-   * @param RepositoryInterface $userRepository
37
-   */
38
-  public function __construct(SubscriptionsProviderInterface $subscriptionsProvider,
39
-                              RepositoryInterface            $userRepository) {
31
+    private SubscriptionsProviderInterface $subscriptionsProvider;
32
+    private RepositoryInterface $userRepository;
33
+
34
+    /**
35
+     * @param SubscriptionsProviderInterface $subscriptionsProvider
36
+     * @param RepositoryInterface $userRepository
37
+     */
38
+    public function __construct(SubscriptionsProviderInterface $subscriptionsProvider,
39
+                                RepositoryInterface            $userRepository) {
40 40
     $this->subscriptionsProvider = $subscriptionsProvider;
41 41
     $this->userRepository = $userRepository;
42
-  }
42
+    }
43 43
 
44 44
 
45
-  /**
46
-   * @Route("/api/{version}/subscriptions/{userId}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_paywall_list_subscriptions", requirements={"id"="\d+"})
47
-   */
48
-  public function getAction(Request $request, int $userId) {
45
+    /**
46
+     * @Route("/api/{version}/subscriptions/{userId}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_paywall_list_subscriptions", requirements={"id"="\d+"})
47
+     */
48
+    public function getAction(Request $request, int $userId) {
49 49
     $subscriptionsProvider = $this->subscriptionsProvider;
50 50
 
51 51
     $filters = [
@@ -58,15 +58,15 @@  discard block
 block discarded – undo
58 58
     $subscriptions = $subscriptionsProvider->getSubscriptions($user, $filters);
59 59
 
60 60
     return new SingleResourceResponse($subscriptions);
61
-  }
61
+    }
62 62
 
63
-  private function findOr404(int $id) {
63
+    private function findOr404(int $id) {
64 64
     $user = $this->userRepository->findOneById($id);
65 65
 
66 66
     if (!$user instanceof UserInterface) {
67
-      throw new NotFoundHttpException(sprintf('User with id "%s" was not found.', $id));
67
+        throw new NotFoundHttpException(sprintf('User with id "%s" was not found.', $id));
68 68
     }
69 69
 
70 70
     return $user;
71
-  }
71
+    }
72 72
 }
Please login to merge, or discard this patch.
src/SWP/Bundle/CoreBundle/Controller/ExternalDataController.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -29,40 +29,40 @@  discard block
 block discarded – undo
29 29
 
30 30
 class ExternalDataController extends AbstractController {
31 31
 
32
-  private PackageRepositoryInterface $packageRepository;
33
-  private FactoryInterface $factory;
34
-
35
-  /**
36
-   * @param PackageRepositoryInterface $packageRepository
37
-   * @param FactoryInterface $factory
38
-   */
39
-  public function __construct(PackageRepositoryInterface $packageRepository, FactoryInterface $factory) {
32
+    private PackageRepositoryInterface $packageRepository;
33
+    private FactoryInterface $factory;
34
+
35
+    /**
36
+     * @param PackageRepositoryInterface $packageRepository
37
+     * @param FactoryInterface $factory
38
+     */
39
+    public function __construct(PackageRepositoryInterface $packageRepository, FactoryInterface $factory) {
40 40
     $this->packageRepository = $packageRepository;
41 41
     $this->factory = $factory;
42
-  }
42
+    }
43 43
 
44
-  /**
45
-   * @Route("/api/{version}/packages/extra/{slug}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PUT"}, name="swp_api_core_add_extra_data")
46
-   */
47
-  public function setAction(Request $request, string $slug): SingleResourceResponseInterface {
44
+    /**
45
+     * @Route("/api/{version}/packages/extra/{slug}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PUT"}, name="swp_api_core_add_extra_data")
46
+     */
47
+    public function setAction(Request $request, string $slug): SingleResourceResponseInterface {
48 48
     $packageRepository = $this->packageRepository;
49 49
     $existingPackage = $packageRepository->findOneBy(['slugline' => $slug]);
50 50
     if (null === $existingPackage) {
51
-      throw new NotFoundHttpException(sprintf('Package with slug %s was not found', $slug));
51
+        throw new NotFoundHttpException(sprintf('Package with slug %s was not found', $slug));
52 52
     }
53 53
 
54 54
     $externalData = $existingPackage->getExternalData();
55 55
     if (null === $externalData) {
56
-      foreach ($externalData as $data) {
56
+        foreach ($externalData as $data) {
57 57
         $packageRepository->remove($data);
58
-      }
59
-      $packageRepository->flush();
58
+        }
59
+        $packageRepository->flush();
60 60
     }
61 61
 
62 62
     if (null !== $request->getContent()) {
63
-      $validJson = self::getArrayFromJson($request->getContent());
64
-      $responseData = [];
65
-      foreach ($validJson as $key => $value) {
63
+        $validJson = self::getArrayFromJson($request->getContent());
64
+        $responseData = [];
65
+        foreach ($validJson as $key => $value) {
66 66
         /** @var ExternalDataInterface $externalData */
67 67
         $externalData = $this->factory->create();
68 68
         $externalData->setKey($key);
@@ -70,45 +70,45 @@  discard block
 block discarded – undo
70 70
         $externalData->setPackage($existingPackage);
71 71
         $packageRepository->persist($externalData);
72 72
         $responseData[$externalData->getKey()] = $externalData->getValue();
73
-      }
74
-      $packageRepository->flush();
73
+        }
74
+        $packageRepository->flush();
75 75
 
76
-      return new SingleResourceResponse($responseData, new ResponseContext(200));
76
+        return new SingleResourceResponse($responseData, new ResponseContext(200));
77 77
     }
78 78
 
79 79
     return new SingleResourceResponse(['Provided request content is not valid JSON'], new ResponseContext(400));
80
-  }
80
+    }
81 81
 
82
-  /**
83
-   * @Route("/api/{version}/packages/extra/{slug}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_get_extra_data")
84
-   */
85
-  public function getAction(string $slug): SingleResourceResponseInterface {
82
+    /**
83
+     * @Route("/api/{version}/packages/extra/{slug}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_get_extra_data")
84
+     */
85
+    public function getAction(string $slug): SingleResourceResponseInterface {
86 86
     $packageRepository = $this->packageRepository;
87 87
     $existingPackage = $packageRepository->findOneBy(['slugline' => $slug]);
88 88
     if (null === $existingPackage) {
89
-      throw new NotFoundHttpException(sprintf('package with slug %s was not found', $slug));
89
+        throw new NotFoundHttpException(sprintf('package with slug %s was not found', $slug));
90 90
     }
91 91
 
92 92
     $externalData = $existingPackage->getExternalData();
93 93
     if (null === $externalData) {
94
-      return new SingleResourceResponse([], new ResponseContext(200));
94
+        return new SingleResourceResponse([], new ResponseContext(200));
95 95
     }
96 96
 
97 97
     $responseData = [];
98 98
     /** @var ExternalDataInterface $data */
99 99
     foreach ($externalData as $data) {
100
-      $responseData[$data->getKey()] = $data->getValue();
100
+        $responseData[$data->getKey()] = $data->getValue();
101 101
     }
102 102
 
103 103
     return new SingleResourceResponse($responseData, new ResponseContext(200));
104
-  }
104
+    }
105 105
 
106
-  private static function getArrayFromJson($jsonString) {
106
+    private static function getArrayFromJson($jsonString) {
107 107
     $jsonArray = json_decode($jsonString, true);
108 108
     if (null === $jsonArray || JSON_ERROR_NONE !== json_last_error()) {
109
-      throw new \UnexpectedValueException('Provided request content is not valid JSON');
109
+        throw new \UnexpectedValueException('Provided request content is not valid JSON');
110 110
     }
111 111
 
112 112
     return $jsonArray;
113
-  }
113
+    }
114 114
 }
Please login to merge, or discard this patch.
src/SWP/Bundle/CoreBundle/Controller/AnalyticsExportController.php 2 patches
Indentation   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -50,33 +50,33 @@  discard block
 block discarded – undo
50 50
 
51 51
 class AnalyticsExportController extends AbstractController {
52 52
 
53
-  protected CacheInterface $cacheProvider;
54
-  protected RepositoryInterface $analyticsReportRepository;
55
-  protected Filesystem $filesystem;
56
-  protected CsvReportFileLocationResolver $csvReportFileLocationResolver;
57
-  protected CachedTenantContextInterface $cachedTenantContext;
58
-  protected RouteRepositoryInterface $routeRepository;
59
-  private MessageBusInterface $messageBus;
60
-  private FormFactoryInterface $formFactory;
61
-  private EventDispatcherInterface $eventDispatcher;
62
-
63
-  /**
64
-   * @param CacheInterface $cacheProvider
65
-   * @param RepositoryInterface $analyticsReportRepository
66
-   * @param Filesystem $filesystem
67
-   * @param CsvReportFileLocationResolver $csvReportFileLocationResolver
68
-   * @param CachedTenantContextInterface $cachedTenantContext
69
-   * @param RouteRepositoryInterface $routeRepository
70
-   * @param MessageBusInterface $messageBus
71
-   * @param FormFactoryInterface $formFactory
72
-   * @param EventDispatcherInterface $eventDispatcher
73
-   */
74
-  public function __construct(CacheInterface                $cacheProvider,
75
-                              RepositoryInterface           $analyticsReportRepository, Filesystem $filesystem,
76
-                              CsvReportFileLocationResolver $csvReportFileLocationResolver,
77
-                              CachedTenantContextInterface  $cachedTenantContext,
78
-                              RouteRepositoryInterface      $routeRepository, MessageBusInterface $messageBus,
79
-                              FormFactoryInterface          $formFactory, EventDispatcherInterface $eventDispatcher) {
53
+    protected CacheInterface $cacheProvider;
54
+    protected RepositoryInterface $analyticsReportRepository;
55
+    protected Filesystem $filesystem;
56
+    protected CsvReportFileLocationResolver $csvReportFileLocationResolver;
57
+    protected CachedTenantContextInterface $cachedTenantContext;
58
+    protected RouteRepositoryInterface $routeRepository;
59
+    private MessageBusInterface $messageBus;
60
+    private FormFactoryInterface $formFactory;
61
+    private EventDispatcherInterface $eventDispatcher;
62
+
63
+    /**
64
+     * @param CacheInterface $cacheProvider
65
+     * @param RepositoryInterface $analyticsReportRepository
66
+     * @param Filesystem $filesystem
67
+     * @param CsvReportFileLocationResolver $csvReportFileLocationResolver
68
+     * @param CachedTenantContextInterface $cachedTenantContext
69
+     * @param RouteRepositoryInterface $routeRepository
70
+     * @param MessageBusInterface $messageBus
71
+     * @param FormFactoryInterface $formFactory
72
+     * @param EventDispatcherInterface $eventDispatcher
73
+     */
74
+    public function __construct(CacheInterface                $cacheProvider,
75
+                                RepositoryInterface           $analyticsReportRepository, Filesystem $filesystem,
76
+                                CsvReportFileLocationResolver $csvReportFileLocationResolver,
77
+                                CachedTenantContextInterface  $cachedTenantContext,
78
+                                RouteRepositoryInterface      $routeRepository, MessageBusInterface $messageBus,
79
+                                FormFactoryInterface          $formFactory, EventDispatcherInterface $eventDispatcher) {
80 80
     $this->cacheProvider = $cacheProvider;
81 81
     $this->analyticsReportRepository = $analyticsReportRepository;
82 82
     $this->filesystem = $filesystem;
@@ -86,15 +86,15 @@  discard block
 block discarded – undo
86 86
     $this->messageBus = $messageBus;
87 87
     $this->formFactory = $formFactory;
88 88
     $this->eventDispatcher = $eventDispatcher;
89
-  }
89
+    }
90 90
 
91 91
 
92
-  /**
93
-   * @Route("/api/{version}/export/analytics/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_analytics_export_post")
94
-   *
95
-   * @throws \Exception
96
-   */
97
-  public function post(Request $request): SingleResourceResponseInterface {
92
+    /**
93
+     * @Route("/api/{version}/export/analytics/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_analytics_export_post")
94
+     *
95
+     * @throws \Exception
96
+     */
97
+    public function post(Request $request): SingleResourceResponseInterface {
98 98
     /** @var UserInterface $currentlyLoggedInUser */
99 99
     $currentlyLoggedInUser = $this->getUser();
100 100
 
@@ -105,46 +105,46 @@  discard block
 block discarded – undo
105 105
     $form->handleRequest($request);
106 106
 
107 107
     if ($form->isSubmitted() && $form->isValid()) {
108
-      $data = $form->getData();
108
+        $data = $form->getData();
109 109
 
110
-      $analyticsReport = new AnalyticsReport();
111
-      $analyticsReport->setAssetId($fileName);
112
-      $analyticsReport->setFileExtension('csv');
113
-      $analyticsReport->setUser($currentlyLoggedInUser);
110
+        $analyticsReport = new AnalyticsReport();
111
+        $analyticsReport->setAssetId($fileName);
112
+        $analyticsReport->setFileExtension('csv');
113
+        $analyticsReport->setUser($currentlyLoggedInUser);
114 114
 
115
-      $exportAnalytics = new ExportAnalytics(
116
-          $data['start'],
117
-          $data['end'],
118
-          $this->cachedTenantContext->getTenant()->getCode(),
119
-          $fileName,
120
-          $currentlyLoggedInUser->getEmail(),
121
-          !empty($data['routes']) ? $this->toIds($data['routes']) : [],
122
-          !empty($data['authors']) ? $this->toIds($data['authors']) : [],
123
-          $data['term'] ?? ''
124
-      );
115
+        $exportAnalytics = new ExportAnalytics(
116
+            $data['start'],
117
+            $data['end'],
118
+            $this->cachedTenantContext->getTenant()->getCode(),
119
+            $fileName,
120
+            $currentlyLoggedInUser->getEmail(),
121
+            !empty($data['routes']) ? $this->toIds($data['routes']) : [],
122
+            !empty($data['authors']) ? $this->toIds($data['authors']) : [],
123
+            $data['term'] ?? ''
124
+        );
125 125
 
126
-      $filters = $this->processFilters(
127
-          $exportAnalytics->getFilters(),
128
-          !empty($data['routes']) ? $data['routes'] : [],
129
-          !empty($data['authors']) ? $data['authors'] : []
130
-      );
126
+        $filters = $this->processFilters(
127
+            $exportAnalytics->getFilters(),
128
+            !empty($data['routes']) ? $data['routes'] : [],
129
+            !empty($data['authors']) ? $data['authors'] : []
130
+        );
131 131
 
132
-      $analyticsReport->setFilters($filters);
132
+        $analyticsReport->setFilters($filters);
133 133
 
134
-      $this->analyticsReportRepository->add($analyticsReport);
134
+        $this->analyticsReportRepository->add($analyticsReport);
135 135
 
136
-      $this->messageBus->dispatch($exportAnalytics);
136
+        $this->messageBus->dispatch($exportAnalytics);
137 137
 
138
-      return new SingleResourceResponse(['status' => 'OK'], new ResponseContext(201));
138
+        return new SingleResourceResponse(['status' => 'OK'], new ResponseContext(201));
139 139
     }
140 140
 
141 141
     return new SingleResourceResponse($form, new ResponseContext(400));
142
-  }
142
+    }
143 143
 
144
-  /**
145
-   * @Route("/api/{version}/export/analytics/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_list_analytics_reports")
146
-   */
147
-  public function listAction(Request $request): ResourcesListResponseInterface {
144
+    /**
145
+     * @Route("/api/{version}/export/analytics/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_list_analytics_reports")
146
+     */
147
+    public function listAction(Request $request): ResourcesListResponseInterface {
148 148
     $sorting = $request->query->all('sorting');
149 149
     $reports = $this->analyticsReportRepository->getPaginatedByCriteria(
150 150
         $this->eventDispatcher,
@@ -154,21 +154,21 @@  discard block
 block discarded – undo
154 154
     );
155 155
 
156 156
     return new ResourcesListResponse($reports);
157
-  }
157
+    }
158 158
 
159
-  /**
160
-   * @Route("/analytics/export/{fileName}", methods={"GET"}, options={"expose"=true}, requirements={"mediaId"=".+"}, name="swp_export_analytics_download")
161
-   */
162
-  public function downloadFile(string $fileName): Response {
159
+    /**
160
+     * @Route("/analytics/export/{fileName}", methods={"GET"}, options={"expose"=true}, requirements={"mediaId"=".+"}, name="swp_export_analytics_download")
161
+     */
162
+    public function downloadFile(string $fileName): Response {
163 163
     $cacheKey = md5(serialize(['analytics_report', $fileName]));
164 164
 
165 165
     $analyticsReport = $this->cacheProvider->get($cacheKey, function () use ($fileName) {
166
-      /* @var AnalyticsReportInterface|null $analyticsReport */
167
-      return $this->analyticsReportRepository->findOneBy(['assetId' => $fileName]);
166
+        /* @var AnalyticsReportInterface|null $analyticsReport */
167
+        return $this->analyticsReportRepository->findOneBy(['assetId' => $fileName]);
168 168
     });
169 169
 
170 170
     if (null === $analyticsReport) {
171
-      throw new NotFoundHttpException('Report file was not found.');
171
+        throw new NotFoundHttpException('Report file was not found.');
172 172
     }
173 173
 
174 174
     $response = new Response();
@@ -187,30 +187,30 @@  discard block
 block discarded – undo
187 187
     $response->setContent($this->filesystem->read($this->csvReportFileLocationResolver->getMediaBasePath() . '/' . $analyticsReport->getAssetId()));
188 188
 
189 189
     return $response;
190
-  }
190
+    }
191 191
 
192
-  private function toIds(array $items): array {
192
+    private function toIds(array $items): array {
193 193
     $ids = [];
194 194
     foreach ($items as $item) {
195
-      foreach ($item as $entity) {
195
+        foreach ($item as $entity) {
196 196
         if (!$entity instanceof PersistableInterface) {
197
-          continue;
197
+            continue;
198 198
         }
199 199
 
200 200
         $ids[] = $entity->getId();
201
-      }
201
+        }
202 202
     }
203 203
 
204 204
     return $ids;
205
-  }
205
+    }
206 206
 
207
-  private function processFilters(array $filters, array $routes, array $authors): array {
207
+    private function processFilters(array $filters, array $routes, array $authors): array {
208 208
     $routeNames = [];
209 209
 
210 210
     foreach ($routes as $route) {
211
-      foreach ($route as $entity) {
211
+        foreach ($route as $entity) {
212 212
         $routeNames[] = $entity->getName();
213
-      }
213
+        }
214 214
     }
215 215
 
216 216
     $filters['routes'] = $routeNames;
@@ -218,13 +218,13 @@  discard block
 block discarded – undo
218 218
     $authorNames = [];
219 219
     /** @var ArticleAuthorInterface $author */
220 220
     foreach ($authors as $author) {
221
-      foreach ($author as $entity) {
221
+        foreach ($author as $entity) {
222 222
         $authorNames[] = $entity->getName();
223
-      }
223
+        }
224 224
     }
225 225
 
226 226
     $filters['authors'] = $authorNames;
227 227
 
228 228
     return $filters;
229
-  }
229
+    }
230 230
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
     $currentlyLoggedInUser = $this->getUser();
100 100
 
101 101
     $now = PublisherDateTime::getCurrentDateTime();
102
-    $fileName = 'analytics-' . $now->format('Y-m-d-H:i:s') . '.csv';
102
+    $fileName = 'analytics-'.$now->format('Y-m-d-H:i:s').'.csv';
103 103
 
104 104
     $form = $this->formFactory->createNamed('', ExportAnalyticsType::class, null, ['method' => $request->getMethod()]);
105 105
     $form->handleRequest($request);
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
   public function downloadFile(string $fileName): Response {
163 163
     $cacheKey = md5(serialize(['analytics_report', $fileName]));
164 164
 
165
-    $analyticsReport = $this->cacheProvider->get($cacheKey, function () use ($fileName) {
165
+    $analyticsReport = $this->cacheProvider->get($cacheKey, function() use ($fileName) {
166 166
       /* @var AnalyticsReportInterface|null $analyticsReport */
167 167
       return $this->analyticsReportRepository->findOneBy(['assetId' => $fileName]);
168 168
     });
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
     $response->setMaxAge(63072000);
185 185
     $response->setSharedMaxAge(63072000);
186 186
     $response->setLastModified($analyticsReport->getUpdatedAt() ?: $analyticsReport->getCreatedAt());
187
-    $response->setContent($this->filesystem->read($this->csvReportFileLocationResolver->getMediaBasePath() . '/' . $analyticsReport->getAssetId()));
187
+    $response->setContent($this->filesystem->read($this->csvReportFileLocationResolver->getMediaBasePath().'/'.$analyticsReport->getAssetId()));
188 188
 
189 189
     return $response;
190 190
   }
Please login to merge, or discard this patch.
src/SWP/Bundle/CoreBundle/Controller/SlideshowController.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -29,28 +29,28 @@  discard block
 block discarded – undo
29 29
 use Symfony\Component\Routing\Annotation\Route;
30 30
 
31 31
 class SlideshowController extends Controller {
32
-  private ArticleRepositoryInterface $articleRepository;
33
-  private SlideshowRepositoryInterface $slideshowRepository;
34
-  private EventDispatcherInterface $eventDispatcher;
32
+    private ArticleRepositoryInterface $articleRepository;
33
+    private SlideshowRepositoryInterface $slideshowRepository;
34
+    private EventDispatcherInterface $eventDispatcher;
35 35
 
36
-  /**
37
-   * @param ArticleRepositoryInterface $articleRepository
38
-   * @param SlideshowRepositoryInterface $slideshowRepository
39
-   * @param EventDispatcherInterface $eventDispatcher
40
-   */
41
-  public function __construct(ArticleRepositoryInterface   $articleRepository,
42
-                              SlideshowRepositoryInterface $slideshowRepository,
43
-                              EventDispatcherInterface     $eventDispatcher) {
36
+    /**
37
+     * @param ArticleRepositoryInterface $articleRepository
38
+     * @param SlideshowRepositoryInterface $slideshowRepository
39
+     * @param EventDispatcherInterface $eventDispatcher
40
+     */
41
+    public function __construct(ArticleRepositoryInterface   $articleRepository,
42
+                                SlideshowRepositoryInterface $slideshowRepository,
43
+                                EventDispatcherInterface     $eventDispatcher) {
44 44
     $this->articleRepository = $articleRepository;
45 45
     $this->slideshowRepository = $slideshowRepository;
46 46
     $this->eventDispatcher = $eventDispatcher;
47
-  }
47
+    }
48 48
 
49 49
 
50
-  /**
51
-   * @Route("/api/{version}/content/slideshows/{articleId}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_slideshows_list")
52
-   */
53
-  public function listAction(Request $request, string $articleId): ResourcesListResponseInterface {
50
+    /**
51
+     * @Route("/api/{version}/content/slideshows/{articleId}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_slideshows_list")
52
+     */
53
+    public function listAction(Request $request, string $articleId): ResourcesListResponseInterface {
54 54
     $repository = $this->slideshowRepository;
55 55
 
56 56
     $article = $this->findArticleOr404($articleId);
@@ -60,29 +60,29 @@  discard block
 block discarded – undo
60 60
     ]), $request->query->all('sorting'), new PaginationData($request));
61 61
 
62 62
     return new ResourcesListResponse($slideshows);
63
-  }
63
+    }
64 64
 
65
-  /**
66
-   * @Route("/api/{version}/content/slideshows/{articleId}/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_get_slideshow", requirements={"id"="\d+"})
67
-   */
68
-  public function getAction($id, string $articleId): SingleResourceResponseInterface {
65
+    /**
66
+     * @Route("/api/{version}/content/slideshows/{articleId}/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_get_slideshow", requirements={"id"="\d+"})
67
+     */
68
+    public function getAction($id, string $articleId): SingleResourceResponseInterface {
69 69
     $article = $this->findArticleOr404($articleId);
70 70
 
71 71
     if (null === $list = $this->slideshowRepository->findOneBy([
72 72
             'id' => $id,
73 73
             'article' => $article,
74 74
         ])) {
75
-      throw new NotFoundHttpException(sprintf('Slideshow with id "%s" was not found.', $id));
75
+        throw new NotFoundHttpException(sprintf('Slideshow with id "%s" was not found.', $id));
76 76
     }
77 77
 
78 78
     return new SingleResourceResponse($list);
79
-  }
79
+    }
80 80
 
81
-  private function findArticleOr404($id) {
81
+    private function findArticleOr404($id) {
82 82
     if (null === $article = $this->articleRepository->findOneById($id)) {
83
-      throw new NotFoundHttpException(sprintf('Article with id "%s" was not found.', $id));
83
+        throw new NotFoundHttpException(sprintf('Article with id "%s" was not found.', $id));
84 84
     }
85 85
 
86 86
     return $article;
87
-  }
87
+    }
88 88
 }
Please login to merge, or discard this patch.