Completed
Push — SWP-2325 ( 9f82a4...ea8abe )
by
unknown
46s
created
src/SWP/Bundle/CoreBundle/Command/FillArticleExtraTableCommand.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
                     if (is_array($extraItem)) {
74 74
                         $extra = ArticleExtraEmbedField::newFromValue($key, $extraItem);
75 75
                     } else {
76
-                        $extra = ArticleExtraTextField::newFromValue($key, (string)$extraItem);
76
+                        $extra = ArticleExtraTextField::newFromValue($key, (string) $extraItem);
77 77
                     }
78 78
                     $extra->setArticle($article);
79 79
                     $this->entityManager->persist($extra);
@@ -113,9 +113,9 @@  discard block
 block discarded – undo
113 113
             return $unserialized;
114 114
         }
115 115
 
116
-        $callback = function ($matches) {
116
+        $callback = function($matches) {
117 117
             $matches[2] = trim(preg_replace('/\s\s+/', ' ', $matches[2]));
118
-            return 's:' . mb_strlen($matches[2]) . ':"' . $matches[2] . '";';
118
+            return 's:'.mb_strlen($matches[2]).':"'.$matches[2].'";';
119 119
         };
120 120
 
121 121
         $fixedData = preg_replace_callback('!s:(\d+):"(.*?)";!s', $callback, $data);
Please login to merge, or discard this patch.
src/SWP/Bundle/CoreBundle/Controller/PackageSeoMediaUploadController.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -94,15 +94,15 @@
 block discarded – undo
94 94
 
95 95
             if ($seoMetadata->getMetaMedia()) {
96 96
                 $metaImage = $seoMetadata->getMetaMedia()->getImage();
97
-                $response['_links']['meta_media_url'] = [ 'href' => $this->mediaManager->getMediaPublicUrl($metaImage)];
97
+                $response['_links']['meta_media_url'] = ['href' => $this->mediaManager->getMediaPublicUrl($metaImage)];
98 98
             }
99 99
             if ($seoMetadata->getOgMedia()) {
100 100
                 $metaImage = $seoMetadata->getOgMedia()->getImage();
101
-                $response['_links']['og_media_url'] = [ 'href' => $this->mediaManager->getMediaPublicUrl($metaImage)];
101
+                $response['_links']['og_media_url'] = ['href' => $this->mediaManager->getMediaPublicUrl($metaImage)];
102 102
             }
103 103
             if ($seoMetadata->getTwitterMedia()) {
104 104
                 $metaImage = $seoMetadata->getTwitterMedia()->getImage();
105
-                $response['_links']['twitter_media_url'] = [ 'href' => $this->mediaManager->getMediaPublicUrl($metaImage)];
105
+                $response['_links']['twitter_media_url'] = ['href' => $this->mediaManager->getMediaPublicUrl($metaImage)];
106 106
             }
107 107
 
108 108
             return new SingleResourceResponse($response, new ResponseContext(201));
Please login to merge, or discard this patch.
src/SWP/Bundle/CoreBundle/Controller/SeoMetadataController.php 2 patches
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -20,10 +20,10 @@  discard block
 block discarded – undo
20 20
 use FOS\RestBundle\Controller\Annotations\Route;
21 21
 
22 22
 class SeoMetadataController extends AbstractController {
23
-  private FormFactoryInterface $formFactory;
24
-  private FactoryInterface $seoMetadataFactory;
25
-  private RepositoryInterface $seoMetadataRepository;
26
-  private EventDispatcherInterface $eventDispatcher;
23
+    private FormFactoryInterface $formFactory;
24
+    private FactoryInterface $seoMetadataFactory;
25
+    private RepositoryInterface $seoMetadataRepository;
26
+    private EventDispatcherInterface $eventDispatcher;
27 27
     protected MediaManagerInterface $mediaManager;
28 28
 
29 29
     /**
@@ -33,29 +33,29 @@  discard block
 block discarded – undo
33 33
      * @param EventDispatcherInterface $eventDispatcher
34 34
      * @param MediaManagerInterface $mediaManager
35 35
      */
36
-  public function __construct(
37
-      FormFactoryInterface $formFactory,
38
-      FactoryInterface $seoMetadataFactory,
39
-      RepositoryInterface  $seoMetadataRepository,
40
-      EventDispatcherInterface $eventDispatcher,
41
-      MediaManagerInterface $mediaManager
42
-  ) {
36
+    public function __construct(
37
+        FormFactoryInterface $formFactory,
38
+        FactoryInterface $seoMetadataFactory,
39
+        RepositoryInterface  $seoMetadataRepository,
40
+        EventDispatcherInterface $eventDispatcher,
41
+        MediaManagerInterface $mediaManager
42
+    ) {
43 43
     $this->formFactory = $formFactory;
44 44
     $this->seoMetadataFactory = $seoMetadataFactory;
45 45
     $this->seoMetadataRepository = $seoMetadataRepository;
46 46
     $this->eventDispatcher = $eventDispatcher;
47
-      $this->mediaManager = $mediaManager;
48
-  }
47
+        $this->mediaManager = $mediaManager;
48
+    }
49 49
 
50
-  /**
51
-   * @Route("/api/{version}/packages/seo/{packageGuid}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PUT"}, name="swp_api_core_seo_metadata_put")
52
-   */
53
-  public function put(Request $request, string $packageGuid): SingleResourceResponse {
50
+    /**
51
+     * @Route("/api/{version}/packages/seo/{packageGuid}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PUT"}, name="swp_api_core_seo_metadata_put")
52
+     */
53
+    public function put(Request $request, string $packageGuid): SingleResourceResponse {
54 54
     $this->eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE);
55 55
 
56 56
     $seoMetadata = $this->seoMetadataRepository->findOneByPackageGuid($packageGuid);
57 57
     if (null === $seoMetadata) {
58
-      $seoMetadata = $this->seoMetadataFactory->create();
58
+        $seoMetadata = $this->seoMetadataFactory->create();
59 59
     }
60 60
 
61 61
     $form = $this->formFactory->createNamed('', SeoMetadataType::class, $seoMetadata, ['method' => $request->getMethod()]);
@@ -63,48 +63,48 @@  discard block
 block discarded – undo
63 63
     $form->handleRequest($request);
64 64
 
65 65
     if ($form->isSubmitted() && $form->isValid()) {
66
-      $seoMetadata->setPackageGuid($packageGuid);
67
-      $this->seoMetadataRepository->add($seoMetadata);
66
+        $seoMetadata->setPackageGuid($packageGuid);
67
+        $this->seoMetadataRepository->add($seoMetadata);
68 68
 
69
-      return new SingleResourceResponse($seoMetadata, new ResponseContext(200));
69
+        return new SingleResourceResponse($seoMetadata, new ResponseContext(200));
70 70
     }
71 71
 
72 72
     return new SingleResourceResponse($form, new ResponseContext(400));
73
-  }
73
+    }
74 74
 
75
-  /**
76
-   * @Route("/api/{version}/packages/seo/{packageGuid}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_seo_metadata_get")
77
-   */
78
-  public function getAction(string $packageGuid): SingleResourceResponse {
75
+    /**
76
+     * @Route("/api/{version}/packages/seo/{packageGuid}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_seo_metadata_get")
77
+     */
78
+    public function getAction(string $packageGuid): SingleResourceResponse {
79 79
     $this->eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE);
80 80
 
81
-      $seoMetadata = $this->seoMetadataRepository->findOneByPackageGuid($packageGuid);
81
+        $seoMetadata = $this->seoMetadataRepository->findOneByPackageGuid($packageGuid);
82 82
     if (null === $seoMetadata) {
83
-      throw new NotFoundHttpException('SEO metadata not found!');
83
+        throw new NotFoundHttpException('SEO metadata not found!');
84 84
     }
85 85
 
86
-      $response = [
87
-          "meta_title" => $seoMetadata->getMetaTitle(),
88
-          "meta_description" => $seoMetadata->getMetaDescription(),
89
-          "og_title" => $seoMetadata->getOgTitle(),
90
-          "og_description" => $seoMetadata->getOgDescription(),
91
-          "twitter_title" => $seoMetadata->getTwitterTitle(),
92
-          "twitter_description" => $seoMetadata->getTwitterDescription(),
93
-      ];
94
-
95
-      if ($seoMetadata->getMetaMedia()) {
96
-          $metaImage = $seoMetadata->getMetaMedia()->getImage();
97
-          $response['_links']['meta_media_url'] = [ 'href' => $this->mediaManager->getMediaPublicUrl($metaImage)];
98
-      }
99
-      if ($seoMetadata->getOgMedia()) {
100
-          $metaImage = $seoMetadata->getOgMedia()->getImage();
101
-          $response['_links']['og_media_url'] = [ 'href' => $this->mediaManager->getMediaPublicUrl($metaImage)];
102
-      }
103
-      if ($seoMetadata->getTwitterMedia()) {
104
-          $metaImage = $seoMetadata->getTwitterMedia()->getImage();
105
-          $response['_links']['twitter_media_url'] = [ 'href' => $this->mediaManager->getMediaPublicUrl($metaImage)];
106
-      }
86
+        $response = [
87
+            "meta_title" => $seoMetadata->getMetaTitle(),
88
+            "meta_description" => $seoMetadata->getMetaDescription(),
89
+            "og_title" => $seoMetadata->getOgTitle(),
90
+            "og_description" => $seoMetadata->getOgDescription(),
91
+            "twitter_title" => $seoMetadata->getTwitterTitle(),
92
+            "twitter_description" => $seoMetadata->getTwitterDescription(),
93
+        ];
94
+
95
+        if ($seoMetadata->getMetaMedia()) {
96
+            $metaImage = $seoMetadata->getMetaMedia()->getImage();
97
+            $response['_links']['meta_media_url'] = [ 'href' => $this->mediaManager->getMediaPublicUrl($metaImage)];
98
+        }
99
+        if ($seoMetadata->getOgMedia()) {
100
+            $metaImage = $seoMetadata->getOgMedia()->getImage();
101
+            $response['_links']['og_media_url'] = [ 'href' => $this->mediaManager->getMediaPublicUrl($metaImage)];
102
+        }
103
+        if ($seoMetadata->getTwitterMedia()) {
104
+            $metaImage = $seoMetadata->getTwitterMedia()->getImage();
105
+            $response['_links']['twitter_media_url'] = [ 'href' => $this->mediaManager->getMediaPublicUrl($metaImage)];
106
+        }
107 107
 
108 108
     return new SingleResourceResponse($response, new ResponseContext(200));
109
-  }
109
+    }
110 110
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -94,15 +94,15 @@
 block discarded – undo
94 94
 
95 95
       if ($seoMetadata->getMetaMedia()) {
96 96
           $metaImage = $seoMetadata->getMetaMedia()->getImage();
97
-          $response['_links']['meta_media_url'] = [ 'href' => $this->mediaManager->getMediaPublicUrl($metaImage)];
97
+          $response['_links']['meta_media_url'] = ['href' => $this->mediaManager->getMediaPublicUrl($metaImage)];
98 98
       }
99 99
       if ($seoMetadata->getOgMedia()) {
100 100
           $metaImage = $seoMetadata->getOgMedia()->getImage();
101
-          $response['_links']['og_media_url'] = [ 'href' => $this->mediaManager->getMediaPublicUrl($metaImage)];
101
+          $response['_links']['og_media_url'] = ['href' => $this->mediaManager->getMediaPublicUrl($metaImage)];
102 102
       }
103 103
       if ($seoMetadata->getTwitterMedia()) {
104 104
           $metaImage = $seoMetadata->getTwitterMedia()->getImage();
105
-          $response['_links']['twitter_media_url'] = [ 'href' => $this->mediaManager->getMediaPublicUrl($metaImage)];
105
+          $response['_links']['twitter_media_url'] = ['href' => $this->mediaManager->getMediaPublicUrl($metaImage)];
106 106
       }
107 107
 
108 108
     return new SingleResourceResponse($response, new ResponseContext(200));
Please login to merge, or discard this patch.
src/SWP/Bundle/CoreBundle/Util/SwpLogger.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -5,13 +5,13 @@
 block discarded – undo
5 5
 class SwpLogger
6 6
 {
7 7
 
8
-    public static function log(string $message,bool $echo = false, string $fileName = 'swp.log')
8
+    public static function log(string $message, bool $echo = false, string $fileName = 'swp.log')
9 9
     {
10 10
         $trace = debug_backtrace()[1];
11
-        $message = '[' . date('Y-m-d H:i:s') . '][' . $trace['class'] . '::' . $trace['function'] . '] ' . $message . PHP_EOL;
11
+        $message = '['.date('Y-m-d H:i:s').']['.$trace['class'].'::'.$trace['function'].'] '.$message.PHP_EOL;
12 12
 
13 13
         if (!empty($fileName)) {
14
-            file_put_contents('/tmp/' . $fileName, $message, FILE_APPEND);
14
+            file_put_contents('/tmp/'.$fileName, $message, FILE_APPEND);
15 15
         }
16 16
         if ($echo) {
17 17
             echo $message;
Please login to merge, or discard this patch.
src/SWP/Bundle/CoreBundle/Controller/ContentListController.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
               'secret' => $token,
98 98
           ];
99 99
 
100
-          $response = $client->request('POST', $url,  [
100
+          $response = $client->request('POST', $url, [
101 101
               'headers' => $headers,
102 102
               'json' => $data,
103 103
               'query' => $queryParams
@@ -116,9 +116,9 @@  discard block
 block discarded – undo
116 116
               ]
117 117
           ];
118 118
 
119
-          file_put_contents('/tmp/cache_invalidation.json', json_encode($result) . PHP_EOL, FILE_APPEND);
119
+          file_put_contents('/tmp/cache_invalidation.json', json_encode($result).PHP_EOL, FILE_APPEND);
120 120
       } catch (\Throwable $e) {
121
-          file_put_contents('/tmp/cache_invalidation_errors.json', $e->getMessage() . PHP_EOL, FILE_APPEND);
121
+          file_put_contents('/tmp/cache_invalidation_errors.json', $e->getMessage().PHP_EOL, FILE_APPEND);
122 122
       }
123 123
   }
124 124
 
Please login to merge, or discard this patch.
Indentation   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -44,36 +44,36 @@  discard block
 block discarded – undo
44 44
 
45 45
 class ContentListController extends AbstractController {
46 46
 
47
-  private ContentListRepositoryInterface $contentListRepository;
48
-  private ContentListItemRepositoryInterface $contentListItemRepository;
49
-  private ContentListServiceInterface $contentListService;
50
-  private FormFactoryInterface $formFactory;
51
-  private EntityManagerInterface $entityManager;
52
-  private EventDispatcherInterface $eventDispatcher;
53
-  private FactoryInterface $factory;
54
-  private string $invalidationCacheUrl;
55
-  private string $invalidationToken;
56
-
57
-  /**
58
-   * @param ContentListRepositoryInterface $contentListRepository
59
-   * @param ContentListItemRepositoryInterface $contentListItemRepository
60
-   * @param ContentListServiceInterface $contentListService
61
-   * @param FormFactoryInterface $formFactory
62
-   * @param EntityManagerInterface $entityManager
63
-   * @param EventDispatcherInterface $eventDispatcher
64
-   * @param FactoryInterface $factory
65
-   */
66
-  public function __construct(
67
-      ContentListRepositoryInterface     $contentListRepository,
68
-      ContentListItemRepositoryInterface $contentListItemRepository,
69
-      ContentListServiceInterface        $contentListService,
70
-      FormFactoryInterface               $formFactory,
71
-      EntityManagerInterface             $entityManager,
72
-      EventDispatcherInterface           $eventDispatcher,
73
-      FactoryInterface                   $factory,
74
-      string $invalidationCacheUrl,
75
-      string $invalidationToken
76
-  ) {
47
+    private ContentListRepositoryInterface $contentListRepository;
48
+    private ContentListItemRepositoryInterface $contentListItemRepository;
49
+    private ContentListServiceInterface $contentListService;
50
+    private FormFactoryInterface $formFactory;
51
+    private EntityManagerInterface $entityManager;
52
+    private EventDispatcherInterface $eventDispatcher;
53
+    private FactoryInterface $factory;
54
+    private string $invalidationCacheUrl;
55
+    private string $invalidationToken;
56
+
57
+    /**
58
+     * @param ContentListRepositoryInterface $contentListRepository
59
+     * @param ContentListItemRepositoryInterface $contentListItemRepository
60
+     * @param ContentListServiceInterface $contentListService
61
+     * @param FormFactoryInterface $formFactory
62
+     * @param EntityManagerInterface $entityManager
63
+     * @param EventDispatcherInterface $eventDispatcher
64
+     * @param FactoryInterface $factory
65
+     */
66
+    public function __construct(
67
+        ContentListRepositoryInterface     $contentListRepository,
68
+        ContentListItemRepositoryInterface $contentListItemRepository,
69
+        ContentListServiceInterface        $contentListService,
70
+        FormFactoryInterface               $formFactory,
71
+        EntityManagerInterface             $entityManager,
72
+        EventDispatcherInterface           $eventDispatcher,
73
+        FactoryInterface                   $factory,
74
+        string $invalidationCacheUrl,
75
+        string $invalidationToken
76
+    ) {
77 77
     $this->contentListRepository = $contentListRepository;
78 78
     $this->contentListItemRepository = $contentListItemRepository;
79 79
     $this->contentListService = $contentListService;
@@ -83,65 +83,65 @@  discard block
 block discarded – undo
83 83
     $this->factory = $factory;
84 84
     $this->invalidationCacheUrl = $invalidationCacheUrl;
85 85
     $this->invalidationToken = $invalidationToken;
86
-  }
87
-
88
-  public static function invalidateCache(string $url, string $token, array $data = [])
89
-  {
90
-      try {
91
-          $client = new Client();
92
-
93
-          $headers = [
94
-              'Content-Type' => 'application/json',
95
-          ];
96
-          $queryParams = [
97
-              'secret' => $token,
98
-          ];
99
-
100
-          $response = $client->request('POST', $url,  [
101
-              'headers' => $headers,
102
-              'json' => $data,
103
-              'query' => $queryParams
104
-          ]);
105
-          $responseBody = $response->getBody()->getContents();
106
-          $result = [
107
-              'request' => [
108
-                  'headers' => $headers,
109
-                  'json' => $data,
110
-                  'query' => $queryParams
111
-              ],
112
-              'response' => [
113
-                  'status' => $response->getStatusCode(),
114
-                  'body' => $responseBody,
115
-                  'ReasonPhrase' => $response->getReasonPhrase()
116
-              ]
117
-          ];
118
-
119
-          file_put_contents('/tmp/cache_invalidation.json', json_encode($result) . PHP_EOL, FILE_APPEND);
120
-      } catch (\Throwable $e) {
121
-          file_put_contents('/tmp/cache_invalidation_errors.json', $e->getMessage() . PHP_EOL, FILE_APPEND);
122
-      }
123
-  }
124
-
125
-  /**
126
-   * @Route("/api/{version}/content/lists/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_content_list_lists")
127
-   */
128
-  public function listAction(Request $request): ResourcesListResponseInterface {
86
+    }
87
+
88
+    public static function invalidateCache(string $url, string $token, array $data = [])
89
+    {
90
+        try {
91
+            $client = new Client();
92
+
93
+            $headers = [
94
+                'Content-Type' => 'application/json',
95
+            ];
96
+            $queryParams = [
97
+                'secret' => $token,
98
+            ];
99
+
100
+            $response = $client->request('POST', $url,  [
101
+                'headers' => $headers,
102
+                'json' => $data,
103
+                'query' => $queryParams
104
+            ]);
105
+            $responseBody = $response->getBody()->getContents();
106
+            $result = [
107
+                'request' => [
108
+                    'headers' => $headers,
109
+                    'json' => $data,
110
+                    'query' => $queryParams
111
+                ],
112
+                'response' => [
113
+                    'status' => $response->getStatusCode(),
114
+                    'body' => $responseBody,
115
+                    'ReasonPhrase' => $response->getReasonPhrase()
116
+                ]
117
+            ];
118
+
119
+            file_put_contents('/tmp/cache_invalidation.json', json_encode($result) . PHP_EOL, FILE_APPEND);
120
+        } catch (\Throwable $e) {
121
+            file_put_contents('/tmp/cache_invalidation_errors.json', $e->getMessage() . PHP_EOL, FILE_APPEND);
122
+        }
123
+    }
124
+
125
+    /**
126
+     * @Route("/api/{version}/content/lists/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_content_list_lists")
127
+     */
128
+    public function listAction(Request $request): ResourcesListResponseInterface {
129 129
     $lists = $this->contentListRepository->getPaginatedByCriteria($this->eventDispatcher, new Criteria(), $request->query->all('sorting'), new PaginationData($request));
130 130
 
131 131
     return new ResourcesListResponse($lists);
132
-  }
132
+    }
133 133
 
134
-  /**
135
-   * @Route("/api/{version}/content/lists/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_content_show_lists", requirements={"id"="\d+"})
136
-   */
137
-  public function getAction($id): SingleResourceResponseInterface {
134
+    /**
135
+     * @Route("/api/{version}/content/lists/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_content_show_lists", requirements={"id"="\d+"})
136
+     */
137
+    public function getAction($id): SingleResourceResponseInterface {
138 138
     return new SingleResourceResponse($this->findOr404($id));
139
-  }
139
+    }
140 140
 
141
-  /**
142
-   * @Route("/api/{version}/content/lists/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_content_create_lists")
143
-   */
144
-  public function createAction(Request $request): SingleResourceResponseInterface {
141
+    /**
142
+     * @Route("/api/{version}/content/lists/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_content_create_lists")
143
+     */
144
+    public function createAction(Request $request): SingleResourceResponseInterface {
145 145
     /* @var ContentListInterface $contentList */
146 146
     $contentList = $this->factory->create();
147 147
     $form = $this->formFactory->createNamed('', ContentListType::class, $contentList, ['method' => $request->getMethod()]);
@@ -150,28 +150,28 @@  discard block
 block discarded – undo
150 150
     $this->ensureContentListExists($contentList->getName());
151 151
 
152 152
     if ($form->isSubmitted() && $form->isValid()) {
153
-      $this->contentListRepository->add($contentList);
154
-      self::invalidateCache(
155
-          $this->invalidationCacheUrl,
156
-          $this->invalidationToken,
157
-          [
158
-              'id' => $contentList->getId(),
159
-              'name' => $contentList->getName(),
160
-              'type' => $contentList->getType(),
161
-              'action' => 'CREATE'
162
-          ]
153
+        $this->contentListRepository->add($contentList);
154
+        self::invalidateCache(
155
+            $this->invalidationCacheUrl,
156
+            $this->invalidationToken,
157
+            [
158
+                'id' => $contentList->getId(),
159
+                'name' => $contentList->getName(),
160
+                'type' => $contentList->getType(),
161
+                'action' => 'CREATE'
162
+            ]
163 163
         );
164 164
 
165
-      return new SingleResourceResponse($contentList, new ResponseContext(201));
165
+        return new SingleResourceResponse($contentList, new ResponseContext(201));
166 166
     }
167 167
 
168 168
     return new SingleResourceResponse($form, new ResponseContext(400));
169
-  }
169
+    }
170 170
 
171
-  /**
172
-   * @Route("/api/{version}/content/lists/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_content_update_lists", requirements={"id"="\d+"})
173
-   */
174
-  public function updateAction(Request $request, int $id): SingleResourceResponseInterface {
171
+    /**
172
+     * @Route("/api/{version}/content/lists/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_content_update_lists", requirements={"id"="\d+"})
173
+     */
174
+    public function updateAction(Request $request, int $id): SingleResourceResponseInterface {
175 175
     $objectManager = $this->entityManager;
176 176
     /** @var ContentListInterface $contentList */
177 177
     $contentList = $this->findOr404($id);
@@ -182,12 +182,12 @@  discard block
 block discarded – undo
182 182
     $form->handleRequest($request);
183 183
 
184 184
     if ($form->isSubmitted() && $form->isValid()) {
185
-      $this->eventDispatcher->dispatch(
186
-          new GenericEvent($contentList, ['filters' => $filters, 'previousLimit' => $listLimit]),
187
-          ContentListEvents::LIST_CRITERIA_CHANGE
188
-      );
185
+        $this->eventDispatcher->dispatch(
186
+            new GenericEvent($contentList, ['filters' => $filters, 'previousLimit' => $listLimit]),
187
+            ContentListEvents::LIST_CRITERIA_CHANGE
188
+        );
189 189
 
190
-      $objectManager->flush();
190
+        $objectManager->flush();
191 191
         self::invalidateCache(
192 192
             $this->invalidationCacheUrl,
193 193
             $this->invalidationToken,
@@ -199,54 +199,54 @@  discard block
 block discarded – undo
199 199
             ]
200 200
         );
201 201
 
202
-      return new SingleResourceResponse($contentList);
202
+        return new SingleResourceResponse($contentList);
203 203
     }
204 204
 
205 205
     return new SingleResourceResponse($form, new ResponseContext(400));
206
-  }
206
+    }
207 207
 
208
-  /**
209
-   * @Route("/api/{version}/content/lists/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_content_delete_lists", requirements={"id"="\d+"})
210
-   */
211
-  public function deleteAction($id): SingleResourceResponseInterface {
208
+    /**
209
+     * @Route("/api/{version}/content/lists/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_content_delete_lists", requirements={"id"="\d+"})
210
+     */
211
+    public function deleteAction($id): SingleResourceResponseInterface {
212 212
     $repository = $this->contentListRepository;
213 213
     $contentList = $this->findOr404($id);
214 214
 
215 215
     $repository->remove($contentList);
216
-      self::invalidateCache(
217
-          $this->invalidationCacheUrl,
218
-          $this->invalidationToken,
219
-          [
220
-              'id' => $contentList->getId(),
221
-              'name' => $contentList->getName(),
222
-              'type' => $contentList->getType(),
223
-              'action' => 'DELETE'
224
-          ]
225
-      );
216
+        self::invalidateCache(
217
+            $this->invalidationCacheUrl,
218
+            $this->invalidationToken,
219
+            [
220
+                'id' => $contentList->getId(),
221
+                'name' => $contentList->getName(),
222
+                'type' => $contentList->getType(),
223
+                'action' => 'DELETE'
224
+            ]
225
+        );
226 226
 
227 227
     return new SingleResourceResponse(null, new ResponseContext(204));
228
-  }
228
+    }
229 229
 
230
-  /**
231
-   * @Route("/api/{version}/content/lists/{id}", requirements={"id"="\w+"}, defaults={"version"="v2"}, methods={"LINK","UNLINK"}, name="swp_api_content_list_link_unlink")
232
-   */
233
-  public function linkUnlinkToContentListAction(Request $request, string $id): SingleResourceResponseInterface {
230
+    /**
231
+     * @Route("/api/{version}/content/lists/{id}", requirements={"id"="\w+"}, defaults={"version"="v2"}, methods={"LINK","UNLINK"}, name="swp_api_content_list_link_unlink")
232
+     */
233
+    public function linkUnlinkToContentListAction(Request $request, string $id): SingleResourceResponseInterface {
234 234
     $objectManager = $this->entityManager;
235 235
     /** @var ContentListInterface $contentList */
236 236
     $contentList = $this->findOr404($id);
237 237
 
238 238
     $matched = false;
239 239
     foreach ($request->attributes->get('links', []) as $key => $objectArray) {
240
-      if (!is_array($objectArray)) {
240
+        if (!is_array($objectArray)) {
241 241
         continue;
242
-      }
242
+        }
243 243
 
244
-      $object = $objectArray['object'];
245
-      if ($object instanceof Exception) {
244
+        $object = $objectArray['object'];
245
+        if ($object instanceof Exception) {
246 246
         throw $object;
247
-      }
247
+        }
248 248
 
249
-      if ($object instanceof ArticleInterface) {
249
+        if ($object instanceof ArticleInterface) {
250 250
         $contentListItem = $this->contentListItemRepository
251 251
             ->findOneBy([
252 252
                 'contentList' => $contentList,
@@ -254,59 +254,59 @@  discard block
 block discarded – undo
254 254
             ]);
255 255
 
256 256
         if ('LINK' === $request->getMethod()) {
257
-          $position = 0;
258
-          if (count($notConvertedLinks = RequestParser::getNotConvertedLinks($request->attributes->get('links'))) > 0) {
257
+            $position = 0;
258
+            if (count($notConvertedLinks = RequestParser::getNotConvertedLinks($request->attributes->get('links'))) > 0) {
259 259
             foreach ($notConvertedLinks as $link) {
260
-              if (isset($link['resourceType']) && 'position' === $link['resourceType']) {
260
+                if (isset($link['resourceType']) && 'position' === $link['resourceType']) {
261 261
                 $position = $link['resource'];
262
-              }
262
+                }
263
+            }
263 264
             }
264
-          }
265 265
 
266
-          if (false === $position && $contentListItem) {
266
+            if (false === $position && $contentListItem) {
267 267
             throw new ConflictHttpException('This content is already linked to Content List');
268
-          }
268
+            }
269 269
 
270
-          if (!$contentListItem) {
270
+            if (!$contentListItem) {
271 271
             $contentListItem = $this->contentListService->addArticleToContentList($contentList, $object, $position);
272 272
             $objectManager->persist($contentListItem);
273
-          } else {
273
+            } else {
274 274
             $contentListItem->setPosition($position);
275
-          }
275
+            }
276 276
 
277
-          $objectManager->flush();
277
+            $objectManager->flush();
278 278
         } elseif ('UNLINK' === $request->getMethod()) {
279
-          if ($contentListItem->getContentList() !== $contentList) {
279
+            if ($contentListItem->getContentList() !== $contentList) {
280 280
             throw new ConflictHttpException('Content is not linked to content list');
281
-          }
282
-          $objectManager->remove($contentListItem);
281
+            }
282
+            $objectManager->remove($contentListItem);
283 283
         }
284 284
 
285 285
         $matched = true;
286 286
 
287 287
         break;
288
-      }
288
+        }
289 289
     }
290 290
     if (false === $matched) {
291
-      throw new NotFoundHttpException('Any supported link object was not found');
291
+        throw new NotFoundHttpException('Any supported link object was not found');
292 292
     }
293 293
 
294 294
     $objectManager->flush();
295 295
 
296 296
     return new SingleResourceResponse($contentList, new ResponseContext(201));
297
-  }
297
+    }
298 298
 
299
-  private function findOr404($id) {
299
+    private function findOr404($id) {
300 300
     if (null === $list = $this->contentListRepository->find($id)) {
301
-      throw new NotFoundHttpException(sprintf('Content list with id "%s" was not found.', $id));
301
+        throw new NotFoundHttpException(sprintf('Content list with id "%s" was not found.', $id));
302 302
     }
303 303
 
304 304
     return $list;
305
-  }
305
+    }
306 306
 
307
-  private function ensureContentListExists($name) {
307
+    private function ensureContentListExists($name) {
308 308
     if (null !== $this->contentListRepository->findOneBy(['name' => $name])) {
309
-      throw new ConflictHttpException(sprintf('Content list named "%s" already exists!', $name));
309
+        throw new ConflictHttpException(sprintf('Content list named "%s" already exists!', $name));
310
+    }
310 311
     }
311
-  }
312 312
 }
Please login to merge, or discard this patch.
src/SWP/Bundle/CoreBundle/Controller/ContentListItemController.php 1 patch
Indentation   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -45,41 +45,41 @@  discard block
 block discarded – undo
45 45
 use FOS\RestBundle\Controller\Annotations\Route;
46 46
 
47 47
 class ContentListItemController extends AbstractController {
48
-  private ContentListItemRepositoryInterface $contentListItemRepository;
49
-  private EntityManagerInterface $entityManager;
50
-  private ContentListServiceInterface $contentListService;
51
-  private EventDispatcherInterface $eventDispatcher;
52
-
53
-  /**
54
-   * @param ContentListItemRepositoryInterface $contentListItemRepository
55
-   * @param EntityManagerInterface $entityManager
56
-   * @param ContentListServiceInterface $contentListService
57
-   * @param EventDispatcherInterface $eventDispatcher
58
-   */
59
-  public function __construct(
60
-      ContentListItemRepositoryInterface $contentListItemRepository,
61
-      EntityManagerInterface $entityManager,
62
-      ContentListServiceInterface $contentListService,
63
-      EventDispatcherInterface $eventDispatcher,
64
-      string $invalidationCacheUrl,
65
-      string $invalidationToken
66
-  ) {
67
-      $this->contentListItemRepository = $contentListItemRepository;
68
-      $this->entityManager = $entityManager;
69
-      $this->contentListService = $contentListService;
70
-      $this->eventDispatcher = $eventDispatcher;
71
-      $this->invalidationCacheUrl = $invalidationCacheUrl;
72
-      $this->invalidationToken = $invalidationToken;
73
-  }
74
-
75
-
76
-  /**
77
-   * @Route("/api/{version}/content/lists/{id}/items/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_list_items", requirements={"id"="\d+"})
78
-   */
79
-  public function listAction(Request $request, int $id): ResourcesListResponseInterface {
48
+    private ContentListItemRepositoryInterface $contentListItemRepository;
49
+    private EntityManagerInterface $entityManager;
50
+    private ContentListServiceInterface $contentListService;
51
+    private EventDispatcherInterface $eventDispatcher;
52
+
53
+    /**
54
+     * @param ContentListItemRepositoryInterface $contentListItemRepository
55
+     * @param EntityManagerInterface $entityManager
56
+     * @param ContentListServiceInterface $contentListService
57
+     * @param EventDispatcherInterface $eventDispatcher
58
+     */
59
+    public function __construct(
60
+        ContentListItemRepositoryInterface $contentListItemRepository,
61
+        EntityManagerInterface $entityManager,
62
+        ContentListServiceInterface $contentListService,
63
+        EventDispatcherInterface $eventDispatcher,
64
+        string $invalidationCacheUrl,
65
+        string $invalidationToken
66
+    ) {
67
+        $this->contentListItemRepository = $contentListItemRepository;
68
+        $this->entityManager = $entityManager;
69
+        $this->contentListService = $contentListService;
70
+        $this->eventDispatcher = $eventDispatcher;
71
+        $this->invalidationCacheUrl = $invalidationCacheUrl;
72
+        $this->invalidationToken = $invalidationToken;
73
+    }
74
+
75
+
76
+    /**
77
+     * @Route("/api/{version}/content/lists/{id}/items/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_list_items", requirements={"id"="\d+"})
78
+     */
79
+    public function listAction(Request $request, int $id): ResourcesListResponseInterface {
80 80
     $sort = $request->query->all('sorting');
81 81
     if (empty($sort)) {
82
-      $sort = ['sticky' => 'desc'];
82
+        $sort = ['sticky' => 'desc'];
83 83
     }
84 84
 
85 85
     $items = $this->contentListItemRepository->getPaginatedByCriteria(
@@ -112,20 +112,20 @@  discard block
 block discarded – undo
112 112
     );
113 113
 
114 114
     return new ResourcesListResponse($items, $responseContext);
115
-  }
115
+    }
116 116
 
117
-  /**
118
-   * @Route("/api/{version}/content/lists/{listId}/items/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_show_lists_item", requirements={"id"="\d+"})
119
-   */
120
-  public function getAction($listId, $id) {
117
+    /**
118
+     * @Route("/api/{version}/content/lists/{listId}/items/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_show_lists_item", requirements={"id"="\d+"})
119
+     */
120
+    public function getAction($listId, $id) {
121 121
     return new SingleResourceResponse($this->findOr404($listId, $id));
122
-  }
122
+    }
123 123
 
124
-  /**
125
-   * @Route("/api/{version}/content/lists/{listId}/items/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_update_lists_item", requirements={"id"="\d+", "listId"="\d+"})
126
-   */
127
-  public function updateAction(Request $request, FormFactoryInterface $formFactory, $listId,
128
-                                       $id): SingleResourceResponseInterface {
124
+    /**
125
+     * @Route("/api/{version}/content/lists/{listId}/items/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_update_lists_item", requirements={"id"="\d+", "listId"="\d+"})
126
+     */
127
+    public function updateAction(Request $request, FormFactoryInterface $formFactory, $listId,
128
+                                        $id): SingleResourceResponseInterface {
129 129
     $contentListItem = $this->findOr404($listId, $id);
130 130
     $form = $formFactory->createNamed(
131 131
         '',
@@ -137,13 +137,13 @@  discard block
 block discarded – undo
137 137
     $form->handleRequest($request);
138 138
 
139 139
     if ($form->isSubmitted() && $form->isValid()) {
140
-      $contentListItem->getContentList()->setUpdatedAt(new DateTime());
140
+        $contentListItem->getContentList()->setUpdatedAt(new DateTime());
141 141
 
142
-      if (null !== $contentListItem->getStickyPosition()) {
142
+        if (null !== $contentListItem->getStickyPosition()) {
143 143
         $contentListItem->setPosition($contentListItem->getStickyPosition());
144
-      }
144
+        }
145 145
 
146
-      $this->entityManager->flush();
146
+        $this->entityManager->flush();
147 147
         ContentListController::invalidateCache(
148 148
             $this->invalidationCacheUrl,
149 149
             $this->invalidationToken,
@@ -155,51 +155,51 @@  discard block
 block discarded – undo
155 155
             ]
156 156
         );
157 157
 
158
-      return new SingleResourceResponse($contentListItem);
158
+        return new SingleResourceResponse($contentListItem);
159 159
     }
160 160
 
161 161
     return new SingleResourceResponse($form, new ResponseContext(400));
162
-  }
163
-
164
-  /**
165
-   * @Route("/api/{version}/content/lists/{listId}/items/", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_batch_update_lists_item", requirements={"listId"="\d+"})
166
-   */
167
-  public function batchUpdateAction(
168
-      Request                        $request,
169
-      FormFactoryInterface           $formFactory,
170
-      ContentListRepositoryInterface $contentListRepository,
171
-      ArticleRepositoryInterface     $articleRepository,
172
-      EventDispatcherInterface       $eventDispatcher,
173
-      int                            $listId
174
-  ): SingleResourceResponseInterface {
162
+    }
163
+
164
+    /**
165
+     * @Route("/api/{version}/content/lists/{listId}/items/", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_batch_update_lists_item", requirements={"listId"="\d+"})
166
+     */
167
+    public function batchUpdateAction(
168
+        Request                        $request,
169
+        FormFactoryInterface           $formFactory,
170
+        ContentListRepositoryInterface $contentListRepository,
171
+        ArticleRepositoryInterface     $articleRepository,
172
+        EventDispatcherInterface       $eventDispatcher,
173
+        int                            $listId
174
+    ): SingleResourceResponseInterface {
175 175
     /** @var ContentListInterface $list */
176 176
     $list = $contentListRepository->findOneBy(['id' => $listId]);
177 177
     if (null === $list) {
178
-      throw new NotFoundHttpException(sprintf('Content list with id "%s" was not found.', $list));
178
+        throw new NotFoundHttpException(sprintf('Content list with id "%s" was not found.', $list));
179 179
     }
180 180
 
181 181
     $form = $formFactory->createNamed('', ContentListItemsType::class, [], ['method' => $request->getMethod()]);
182 182
 
183 183
     $form->handleRequest($request);
184 184
     if ($form->isSubmitted() && $form->isValid()) {
185
-      $data = $form->getData();
186
-      $updatedAt = DateTime::createFromFormat(DateTime::RFC3339, $data['updatedAt'], new DateTimeZone('UTC'));
187
-      $updatedAt->setTimezone(new DateTimeZone('UTC'));
188
-      $listUpdatedAt = $list->getUpdatedAt();
189
-      $listUpdatedAt->setTimezone(new DateTimeZone('UTC'));
190
-      if ($updatedAt < $listUpdatedAt) {
185
+        $data = $form->getData();
186
+        $updatedAt = DateTime::createFromFormat(DateTime::RFC3339, $data['updatedAt'], new DateTimeZone('UTC'));
187
+        $updatedAt->setTimezone(new DateTimeZone('UTC'));
188
+        $listUpdatedAt = $list->getUpdatedAt();
189
+        $listUpdatedAt->setTimezone(new DateTimeZone('UTC'));
190
+        if ($updatedAt < $listUpdatedAt) {
191 191
         throw new ConflictHttpException('List was already updated');
192
-      }
192
+        }
193 193
 
194
-      $updatedArticles = [];
195
-      /** @var ContentListAction $item */
196
-      foreach ($data['items'] as $item) {
194
+        $updatedArticles = [];
195
+        /** @var ContentListAction $item */
196
+        foreach ($data['items'] as $item) {
197 197
         $position = $item->getPosition();
198 198
         $isSticky = $item->isSticky();
199 199
         $contentId = $item->getContentId();
200 200
 
201 201
         switch ($item->getAction()) {
202
-          case ContentListAction::ACTION_MOVE:
202
+            case ContentListAction::ACTION_MOVE:
203 203
             $updated = false;
204 204
             $contentListItem = $this->findByContentOr404($list, $contentId);
205 205
 
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
             $updatedArticles[$contentId] = $contentListItem->getContent();
228 228
 
229 229
             break;
230
-          case ContentListAction::ACTION_ADD:
230
+            case ContentListAction::ACTION_ADD:
231 231
             $this->ensureThereIsNoItemOnPositionOrThrow409(
232 232
                 $listId,
233 233
                 $position,
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
             $updatedArticles[$contentId] = $contentListItem->getContent();
242 242
 
243 243
             break;
244
-          case ContentListAction::ACTION_DELETE:
244
+            case ContentListAction::ACTION_DELETE:
245 245
             $contentListItem = $this->findByContentOr404($list, $contentId);
246 246
             $this->entityManager->remove($contentListItem);
247 247
             $list->setUpdatedAt(new DateTime('now'));
@@ -250,17 +250,17 @@  discard block
 block discarded – undo
250 250
 
251 251
             break;
252 252
         }
253
-      }
253
+        }
254 254
 
255
-      $this->contentListService->repositionStickyItems($list);
255
+        $this->contentListService->repositionStickyItems($list);
256 256
 
257
-      foreach ($updatedArticles as $updatedArticle) {
257
+        foreach ($updatedArticles as $updatedArticle) {
258 258
         $eventDispatcher->dispatch(new ArticleEvent(
259 259
             $updatedArticle,
260 260
             $updatedArticle->getPackage(),
261 261
             ArticleEvents::POST_UPDATE
262 262
         ), ArticleEvents::POST_UPDATE);
263
-      }
263
+        }
264 264
         ContentListController::invalidateCache(
265 265
             $this->invalidationCacheUrl,
266 266
             $this->invalidationToken,
@@ -272,13 +272,13 @@  discard block
 block discarded – undo
272 272
             ]
273 273
         );
274 274
 
275
-      return new SingleResourceResponse($list, new ResponseContext(201));
275
+        return new SingleResourceResponse($list, new ResponseContext(201));
276 276
     }
277 277
 
278 278
     return new SingleResourceResponse($form, new ResponseContext(400));
279
-  }
279
+    }
280 280
 
281
-  private function findByContentOr404($listId, $contentId): ContentListItemInterface {
281
+    private function findByContentOr404($listId, $contentId): ContentListItemInterface {
282 282
     /** @var ContentListItemInterface $listItem */
283 283
     $listItem = $this->contentListItemRepository->findOneBy([
284 284
         'contentList' => $listId,
@@ -286,13 +286,13 @@  discard block
 block discarded – undo
286 286
     ]);
287 287
 
288 288
     if (null === $listItem) {
289
-      throw new NotFoundHttpException(sprintf('Content list item with content_id "%s" was not found on that list. If You want to add new item - use action type "add".', $contentId));
289
+        throw new NotFoundHttpException(sprintf('Content list item with content_id "%s" was not found on that list. If You want to add new item - use action type "add".', $contentId));
290 290
     }
291 291
 
292 292
     return $listItem;
293
-  }
293
+    }
294 294
 
295
-  private function findOr404($listId, $id): ContentListItemInterface {
295
+    private function findOr404($listId, $id): ContentListItemInterface {
296 296
     /** @var ContentListItemInterface $listItem */
297 297
     $listItem = $this->contentListItemRepository->findOneBy([
298 298
         'contentList' => $listId,
@@ -300,29 +300,29 @@  discard block
 block discarded – undo
300 300
     ]);
301 301
 
302 302
     if (null === $listItem) {
303
-      throw new NotFoundHttpException(sprintf('Content list item with id "%s" was not found.', $id));
303
+        throw new NotFoundHttpException(sprintf('Content list item with id "%s" was not found.', $id));
304 304
     }
305 305
 
306 306
     return $listItem;
307
-  }
307
+    }
308 308
 
309
-  private function ensureThereIsNoItemOnPositionOrThrow409(
310
-      int $listId,
311
-      int $position,
312
-      bool $isSticky,
313
-      string $action): void {
314
-      $existingContentListItem = $this->contentListService->isAnyItemPinnedOnPosition($listId, $position);
309
+    private function ensureThereIsNoItemOnPositionOrThrow409(
310
+        int $listId,
311
+        int $position,
312
+        bool $isSticky,
313
+        string $action): void {
314
+        $existingContentListItem = $this->contentListService->isAnyItemPinnedOnPosition($listId, $position);
315 315
 
316
-      if (!$existingContentListItem && !$isSticky) {
317
-          return;
318
-      }
316
+        if (!$existingContentListItem && !$isSticky) {
317
+            return;
318
+        }
319 319
 
320
-      if ($existingContentListItem && $existingContentListItem->isSticky()) {
320
+        if ($existingContentListItem && $existingContentListItem->isSticky()) {
321 321
         throw new ConflictHttpException('There is already an item pinned on that position. Unpin it first.');
322
-      }
322
+        }
323 323
 
324
-      if ($action === ContentListAction::ACTION_MOVE && $isSticky) {
325
-          throw new ConflictHttpException('Cannot move pinned item. Unpin it first.');
326
-      }
327
-  }
324
+        if ($action === ContentListAction::ACTION_MOVE && $isSticky) {
325
+            throw new ConflictHttpException('Cannot move pinned item. Unpin it first.');
326
+        }
327
+    }
328 328
 }
Please login to merge, or discard this patch.
src/SWP/Bundle/ContentBundle/Controller/ArticleController.php 1 patch
Indentation   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -36,27 +36,27 @@  discard block
 block discarded – undo
36 36
 
37 37
 class ArticleController extends AbstractController {
38 38
 
39
-  private FormFactoryInterface $formFactory;
40
-  private RouteProviderInterface $routeProvider; // swp.provider.route
41
-  private ArticleRepositoryInterface $articleRepository; //swp.repository.article
42
-  private ArticleProviderInterface $articleProvider; //swp.provider.article
43
-  private EventDispatcherInterface  $eventDispatcher;
44
-  private EntityManagerInterface $entityManager; // swp.object_manager.article
45
-  private ArticleServiceInterface $articleService; // swp.service.article
46
-
47
-  /**
48
-   * @param FormFactoryInterface $formFactory
49
-   * @param RouteProviderInterface $routeProvider
50
-   * @param ArticleRepositoryInterface $articleRepository
51
-   * @param ArticleProviderInterface $articleProvider
52
-   * @param EventDispatcherInterface $eventDispatcher
53
-   * @param EntityManagerInterface $entityManager
54
-   * @param ArticleServiceInterface $articleService
55
-   */
56
-  public function __construct(FormFactoryInterface       $formFactory, RouteProviderInterface $routeProvider,
57
-                              ArticleRepositoryInterface $articleRepository, ArticleProviderInterface $articleProvider,
58
-                              EventDispatcherInterface   $eventDispatcher, EntityManagerInterface $entityManager,
59
-                              ArticleServiceInterface    $articleService) {
39
+    private FormFactoryInterface $formFactory;
40
+    private RouteProviderInterface $routeProvider; // swp.provider.route
41
+    private ArticleRepositoryInterface $articleRepository; //swp.repository.article
42
+    private ArticleProviderInterface $articleProvider; //swp.provider.article
43
+    private EventDispatcherInterface  $eventDispatcher;
44
+    private EntityManagerInterface $entityManager; // swp.object_manager.article
45
+    private ArticleServiceInterface $articleService; // swp.service.article
46
+
47
+    /**
48
+     * @param FormFactoryInterface $formFactory
49
+     * @param RouteProviderInterface $routeProvider
50
+     * @param ArticleRepositoryInterface $articleRepository
51
+     * @param ArticleProviderInterface $articleProvider
52
+     * @param EventDispatcherInterface $eventDispatcher
53
+     * @param EntityManagerInterface $entityManager
54
+     * @param ArticleServiceInterface $articleService
55
+     */
56
+    public function __construct(FormFactoryInterface       $formFactory, RouteProviderInterface $routeProvider,
57
+                                ArticleRepositoryInterface $articleRepository, ArticleProviderInterface $articleProvider,
58
+                                EventDispatcherInterface   $eventDispatcher, EntityManagerInterface $entityManager,
59
+                                ArticleServiceInterface    $articleService) {
60 60
     $this->formFactory = $formFactory;
61 61
     $this->routeProvider = $routeProvider;
62 62
     $this->articleRepository = $articleRepository;
@@ -64,30 +64,30 @@  discard block
 block discarded – undo
64 64
     $this->eventDispatcher = $eventDispatcher;
65 65
     $this->entityManager = $entityManager;
66 66
     $this->articleService = $articleService;
67
-  }
67
+    }
68 68
 
69 69
 
70
-  /**
71
-   * @Route("/api/{version}/content/articles/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_list_articles")
72
-   *
73
-   * @throws \Exception
74
-   */
75
-  public function listAction(Request $request): ResourcesListResponseInterface {
70
+    /**
71
+     * @Route("/api/{version}/content/articles/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_list_articles")
72
+     *
73
+     * @throws \Exception
74
+     */
75
+    public function listAction(Request $request): ResourcesListResponseInterface {
76 76
     $authors = '';
77 77
     if (null !== $request->query->get('author', null)) {
78
-      $authors = explode(', ', $request->query->get('author'));
78
+        $authors = explode(', ', $request->query->get('author'));
79 79
     }
80 80
 
81 81
     if ($request->query->get('route', false) && $request->query->get('includeSubRoutes', false)) {
82
-      $routeObject = $this->routeProvider->getOneById($request->query->get('route'));
82
+        $routeObject = $this->routeProvider->getOneById($request->query->get('route'));
83 83
 
84
-      if (null !== $routeObject) {
84
+        if (null !== $routeObject) {
85 85
         $ids = [$routeObject->getId()];
86 86
         foreach ($routeObject->getChildren() as $child) {
87
-          $ids[] = $child->getId();
87
+            $ids[] = $child->getId();
88 88
         }
89 89
         $request->query->set('route', $ids);
90
-      }
90
+        }
91 91
     }
92 92
 
93 93
     $articles = $this->articleRepository
@@ -102,25 +102,25 @@  discard block
 block discarded – undo
102 102
         ]), $request->query->all('sorting'), new PaginationData($request));
103 103
 
104 104
     return new ResourcesListResponse($articles);
105
-  }
105
+    }
106 106
 
107
-  /**
108
-   * @Route("/api/{version}/content/articles/{id}", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_show_articles", requirements={"id"=".+"})
109
-   */
110
-  public function getAction($id): SingleResourceResponseInterface {
107
+    /**
108
+     * @Route("/api/{version}/content/articles/{id}", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_show_articles", requirements={"id"=".+"})
109
+     */
110
+    public function getAction($id): SingleResourceResponseInterface {
111 111
     $article = $this->articleProvider->getOneById($id);
112 112
 
113 113
     if (null === $article) {
114
-      throw new NotFoundHttpException('Article was not found');
114
+        throw new NotFoundHttpException('Article was not found');
115 115
     }
116 116
 
117 117
     return new SingleResourceResponse($article);
118
-  }
118
+    }
119 119
 
120
-  /**
121
-   * @Route("/api/{version}/content/article/search-code", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_show_articles_by_code", requirements={"code"=".+"})
122
-   */
123
-  public function getByCodeAction(Request $request): SingleResourceResponseInterface {
120
+    /**
121
+     * @Route("/api/{version}/content/article/search-code", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_show_articles_by_code", requirements={"code"=".+"})
122
+     */
123
+    public function getByCodeAction(Request $request): SingleResourceResponseInterface {
124 124
     // Extract parameters from the request
125 125
     $code = $request->query->get('code', '');
126 126
     //$tenantCode = $request->query->get('tenant_code', '');
@@ -134,16 +134,16 @@  discard block
 block discarded – undo
134 134
         ->getOneOrNullResult();
135 135
 
136 136
     if (null === $article) {
137
-      throw new NotFoundHttpException('Article was not found');
137
+        throw new NotFoundHttpException('Article was not found');
138 138
     }
139 139
 
140 140
     return new SingleResourceResponse($article);
141
-  }
141
+    }
142 142
 
143
-  /**
144
-   * @Route("/api/{version}/content/articles/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_update_articles", requirements={"id"=".+"})
145
-   */
146
-  public function updateAction(Request $request, $id): SingleResourceResponseInterface {
143
+    /**
144
+     * @Route("/api/{version}/content/articles/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_update_articles", requirements={"id"=".+"})
145
+     */
146
+    public function updateAction(Request $request, $id): SingleResourceResponseInterface {
147 147
     $objectManager = $this->entityManager;
148 148
     $article = $this->findOr404($id);
149 149
     $originalArticleStatus = $article->getStatus();
@@ -152,32 +152,32 @@  discard block
 block discarded – undo
152 152
 
153 153
     $form->handleRequest($request);
154 154
     if ($form->isSubmitted() && $form->isValid()) {
155
-      $this->articleService->reactOnStatusChange($originalArticleStatus, $article);
156
-      $objectManager->flush();
157
-      $objectManager->refresh($article);
155
+        $this->articleService->reactOnStatusChange($originalArticleStatus, $article);
156
+        $objectManager->flush();
157
+        $objectManager->refresh($article);
158 158
 
159
-      return new SingleResourceResponse($article);
159
+        return new SingleResourceResponse($article);
160 160
     }
161 161
 
162 162
     return new SingleResourceResponse($form, new ResponseContext(500));
163
-  }
163
+    }
164 164
 
165
-  /**
166
-   * @Route("/api/{version}/content/articles/{id}", methods={"DELETE"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_delete_articles", requirements={"id"=".+"})
167
-   */
168
-  public function deleteAction($id): SingleResourceResponseInterface {
165
+    /**
166
+     * @Route("/api/{version}/content/articles/{id}", methods={"DELETE"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_delete_articles", requirements={"id"=".+"})
167
+     */
168
+    public function deleteAction($id): SingleResourceResponseInterface {
169 169
     $objectManager = $this->entityManager;
170 170
     $objectManager->remove($this->findOr404($id));
171 171
     $objectManager->flush();
172 172
 
173 173
     return new SingleResourceResponse(null, new ResponseContext(204));
174
-  }
174
+    }
175 175
 
176
-  private function findOr404($id) {
176
+    private function findOr404($id) {
177 177
     if (null === $article = $this->articleProvider->getOneById($id)) {
178
-      throw new NotFoundHttpException('Article was not found.');
178
+        throw new NotFoundHttpException('Article was not found.');
179 179
     }
180 180
 
181 181
     return $article;
182
-  }
182
+    }
183 183
 }
Please login to merge, or discard this patch.
src/SWP/Bundle/CoreBundle/EventListener/UpdateContentListItemsListener.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@
 block discarded – undo
84 84
             $subject = $metadata['subject'] ?? [];
85 85
             foreach ($subject as $key => $item) {
86 86
                 if (isset($item['scheme']) && $item['scheme'] == 'urgency') {
87
-                    $filters['metadata']['subject'][$key]['code'] = (string)$item['code'];
87
+                    $filters['metadata']['subject'][$key]['code'] = (string) $item['code'];
88 88
                 }
89 89
             }
90 90
             $criteria = new Criteria($filters);
Please login to merge, or discard this patch.
src/SWP/Bundle/CoreBundle/MessageHandler/AbstractContentPushHandler.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -144,10 +144,10 @@  discard block
 block discarded – undo
144 144
                     ),
145 145
                     Events::PACKAGE_PRE_OPTIONS);
146 146
             }
147
-            $this->eventDispatcher->dispatch( new GenericEvent($existingPackage, ['eventName' => Events::PACKAGE_PRE_UPDATE]), Events::PACKAGE_PRE_UPDATE);
147
+            $this->eventDispatcher->dispatch(new GenericEvent($existingPackage, ['eventName' => Events::PACKAGE_PRE_UPDATE]), Events::PACKAGE_PRE_UPDATE);
148 148
             $this->packageObjectManager->flush();
149
-            $this->eventDispatcher->dispatch( new GenericEvent($existingPackage, ['eventName' => Events::PACKAGE_POST_UPDATE]), Events::PACKAGE_POST_UPDATE);
150
-            $this->eventDispatcher->dispatch( new GenericEvent($existingPackage, ['eventName' => Events::PACKAGE_PROCESSED]), Events::PACKAGE_PROCESSED);
149
+            $this->eventDispatcher->dispatch(new GenericEvent($existingPackage, ['eventName' => Events::PACKAGE_POST_UPDATE]), Events::PACKAGE_POST_UPDATE);
150
+            $this->eventDispatcher->dispatch(new GenericEvent($existingPackage, ['eventName' => Events::PACKAGE_PROCESSED]), Events::PACKAGE_PROCESSED);
151 151
             $this->packageObjectManager->flush();
152 152
 
153 153
             $this->logger->info(sprintf('Package %s was updated', $existingPackage->getGuid()));
@@ -176,10 +176,10 @@  discard block
 block discarded – undo
176 176
             );
177 177
         }
178 178
 
179
-        $this->eventDispatcher->dispatch( new GenericEvent($package, ['eventName' => Events::PACKAGE_PRE_CREATE]), Events::PACKAGE_PRE_CREATE);
179
+        $this->eventDispatcher->dispatch(new GenericEvent($package, ['eventName' => Events::PACKAGE_PRE_CREATE]), Events::PACKAGE_PRE_CREATE);
180 180
         $this->packageRepository->add($package);
181
-        $this->eventDispatcher->dispatch( new GenericEvent($package, ['eventName' => Events::PACKAGE_POST_CREATE]), Events::PACKAGE_POST_CREATE);
182
-        $this->eventDispatcher->dispatch( new GenericEvent($package, ['eventName' => Events::PACKAGE_PROCESSED]), Events::PACKAGE_PROCESSED);
181
+        $this->eventDispatcher->dispatch(new GenericEvent($package, ['eventName' => Events::PACKAGE_POST_CREATE]), Events::PACKAGE_POST_CREATE);
182
+        $this->eventDispatcher->dispatch(new GenericEvent($package, ['eventName' => Events::PACKAGE_PROCESSED]), Events::PACKAGE_PROCESSED);
183 183
 
184 184
         if (!empty($options)) {
185 185
             $this->eventDispatcher->dispatch(
Please login to merge, or discard this patch.