Completed
Push — SWP-2317 ( 4633c4...13e1e0 )
by
unknown
45s
created
src/SWP/Bundle/ContentBundle/Controller/ArticleController.php 1 patch
Indentation   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -37,29 +37,29 @@  discard block
 block discarded – undo
37 37
 
38 38
 class ArticleController extends AbstractController {
39 39
 
40
-  private FormFactoryInterface $formFactory;
41
-  private RouteProviderInterface $routeProvider; // swp.provider.route
42
-  private ArticleRepositoryInterface $articleRepository; //swp.repository.article
43
-  private ArticleProviderInterface $articleProvider; //swp.provider.article
44
-  private EventDispatcherInterface  $eventDispatcher;
45
-  private EntityManagerInterface $entityManager; // swp.object_manager.article
46
-  private ArticleServiceInterface $articleService; // swp.service.article
47
-  private PackageRepositoryInterface $packageRepository;
48
-
49
-  /**
50
-   * @param FormFactoryInterface $formFactory
51
-   * @param RouteProviderInterface $routeProvider
52
-   * @param ArticleRepositoryInterface $articleRepository
53
-   * @param ArticleProviderInterface $articleProvider
54
-   * @param EventDispatcherInterface $eventDispatcher
55
-   * @param EntityManagerInterface $entityManager
56
-   * @param ArticleServiceInterface $articleService
57
-   * @param PackageRepositoryInterface $packageRepository
58
-   */
59
-  public function __construct(FormFactoryInterface       $formFactory, RouteProviderInterface $routeProvider,
60
-                              ArticleRepositoryInterface $articleRepository, ArticleProviderInterface $articleProvider,
61
-                              EventDispatcherInterface   $eventDispatcher, EntityManagerInterface $entityManager,
62
-                              ArticleServiceInterface    $articleService, PackageRepositoryInterface   $packageRepository) {
40
+    private FormFactoryInterface $formFactory;
41
+    private RouteProviderInterface $routeProvider; // swp.provider.route
42
+    private ArticleRepositoryInterface $articleRepository; //swp.repository.article
43
+    private ArticleProviderInterface $articleProvider; //swp.provider.article
44
+    private EventDispatcherInterface  $eventDispatcher;
45
+    private EntityManagerInterface $entityManager; // swp.object_manager.article
46
+    private ArticleServiceInterface $articleService; // swp.service.article
47
+    private PackageRepositoryInterface $packageRepository;
48
+
49
+    /**
50
+     * @param FormFactoryInterface $formFactory
51
+     * @param RouteProviderInterface $routeProvider
52
+     * @param ArticleRepositoryInterface $articleRepository
53
+     * @param ArticleProviderInterface $articleProvider
54
+     * @param EventDispatcherInterface $eventDispatcher
55
+     * @param EntityManagerInterface $entityManager
56
+     * @param ArticleServiceInterface $articleService
57
+     * @param PackageRepositoryInterface $packageRepository
58
+     */
59
+    public function __construct(FormFactoryInterface       $formFactory, RouteProviderInterface $routeProvider,
60
+                                ArticleRepositoryInterface $articleRepository, ArticleProviderInterface $articleProvider,
61
+                                EventDispatcherInterface   $eventDispatcher, EntityManagerInterface $entityManager,
62
+                                ArticleServiceInterface    $articleService, PackageRepositoryInterface   $packageRepository) {
63 63
     $this->formFactory = $formFactory;
64 64
     $this->routeProvider = $routeProvider;
65 65
     $this->articleRepository = $articleRepository;
@@ -68,30 +68,30 @@  discard block
 block discarded – undo
68 68
     $this->entityManager = $entityManager;
69 69
     $this->articleService = $articleService;
70 70
     $this->packageRepository = $packageRepository;
71
-  }
71
+    }
72 72
 
73 73
 
74
-  /**
75
-   * @Route("/api/{version}/content/articles/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_list_articles")
76
-   *
77
-   * @throws \Exception
78
-   */
79
-  public function listAction(Request $request): ResourcesListResponseInterface {
74
+    /**
75
+     * @Route("/api/{version}/content/articles/", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_list_articles")
76
+     *
77
+     * @throws \Exception
78
+     */
79
+    public function listAction(Request $request): ResourcesListResponseInterface {
80 80
     $authors = '';
81 81
     if (null !== $request->query->get('author', null)) {
82
-      $authors = explode(', ', $request->query->get('author'));
82
+        $authors = explode(', ', $request->query->get('author'));
83 83
     }
84 84
 
85 85
     if ($request->query->get('route', false) && $request->query->get('includeSubRoutes', false)) {
86
-      $routeObject = $this->routeProvider->getOneById($request->query->get('route'));
86
+        $routeObject = $this->routeProvider->getOneById($request->query->get('route'));
87 87
 
88
-      if (null !== $routeObject) {
88
+        if (null !== $routeObject) {
89 89
         $ids = [$routeObject->getId()];
90 90
         foreach ($routeObject->getChildren() as $child) {
91
-          $ids[] = $child->getId();
91
+            $ids[] = $child->getId();
92 92
         }
93 93
         $request->query->set('route', $ids);
94
-      }
94
+        }
95 95
     }
96 96
 
97 97
     $articles = $this->articleRepository
@@ -106,31 +106,31 @@  discard block
 block discarded – undo
106 106
         ]), $request->query->all('sorting'), new PaginationData($request));
107 107
 
108 108
     return new ResourcesListResponse($articles);
109
-  }
109
+    }
110 110
 
111
-  /**
112
-   * @Route("/api/{version}/content/articles/{id}", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_show_articles", requirements={"id"=".+"})
113
-   */
114
-  public function getAction($id): SingleResourceResponseInterface {
111
+    /**
112
+     * @Route("/api/{version}/content/articles/{id}", methods={"GET"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_show_articles", requirements={"id"=".+"})
113
+     */
114
+    public function getAction($id): SingleResourceResponseInterface {
115 115
     $article = $this->articleProvider->getOneById($id);
116 116
 
117 117
     if (null === $article) {
118
-      throw new NotFoundHttpException('Article was not found');
118
+        throw new NotFoundHttpException('Article was not found');
119 119
     }
120 120
 
121 121
     return new SingleResourceResponse($article);
122
-  }
122
+    }
123 123
 
124
-  /**
125
-   * @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"=".+"})
126
-   */
127
-  public function getByCodeAction(Request $request): SingleResourceResponseInterface {
124
+    /**
125
+     * @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"=".+"})
126
+     */
127
+    public function getByCodeAction(Request $request): SingleResourceResponseInterface {
128 128
     // Extract parameters from the request
129 129
     $code = $request->query->get('code', '');
130 130
     $article = $this->articleRepository->findOneBy(['code' => $code]);
131 131
 
132 132
     if (null === $article) {
133
-      throw new NotFoundHttpException('Article was not found');
133
+        throw new NotFoundHttpException('Article was not found');
134 134
     }
135 135
 
136 136
     $article->setStatus('new');
@@ -151,12 +151,12 @@  discard block
 block discarded – undo
151 151
     }
152 152
 
153 153
     return new SingleResourceResponse($article);
154
-  }
154
+    }
155 155
 
156
-  /**
157
-   * @Route("/api/{version}/content/articles/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_update_articles", requirements={"id"=".+"})
158
-   */
159
-  public function updateAction(Request $request, $id): SingleResourceResponseInterface {
156
+    /**
157
+     * @Route("/api/{version}/content/articles/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_update_articles", requirements={"id"=".+"})
158
+     */
159
+    public function updateAction(Request $request, $id): SingleResourceResponseInterface {
160 160
     $objectManager = $this->entityManager;
161 161
     $article = $this->findOr404($id);
162 162
     $originalArticleStatus = $article->getStatus();
@@ -165,32 +165,32 @@  discard block
 block discarded – undo
165 165
 
166 166
     $form->handleRequest($request);
167 167
     if ($form->isSubmitted() && $form->isValid()) {
168
-      $this->articleService->reactOnStatusChange($originalArticleStatus, $article);
169
-      $objectManager->flush();
170
-      $objectManager->refresh($article);
168
+        $this->articleService->reactOnStatusChange($originalArticleStatus, $article);
169
+        $objectManager->flush();
170
+        $objectManager->refresh($article);
171 171
 
172
-      return new SingleResourceResponse($article);
172
+        return new SingleResourceResponse($article);
173 173
     }
174 174
 
175 175
     return new SingleResourceResponse($form, new ResponseContext(500));
176
-  }
176
+    }
177 177
 
178
-  /**
179
-   * @Route("/api/{version}/content/articles/{id}", methods={"DELETE"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_delete_articles", requirements={"id"=".+"})
180
-   */
181
-  public function deleteAction($id): SingleResourceResponseInterface {
178
+    /**
179
+     * @Route("/api/{version}/content/articles/{id}", methods={"DELETE"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_delete_articles", requirements={"id"=".+"})
180
+     */
181
+    public function deleteAction($id): SingleResourceResponseInterface {
182 182
     $objectManager = $this->entityManager;
183 183
     $objectManager->remove($this->findOr404($id));
184 184
     $objectManager->flush();
185 185
 
186 186
     return new SingleResourceResponse(null, new ResponseContext(204));
187
-  }
187
+    }
188 188
 
189
-  private function findOr404($id) {
189
+    private function findOr404($id) {
190 190
     if (null === $article = $this->articleProvider->getOneById($id)) {
191
-      throw new NotFoundHttpException('Article was not found.');
191
+        throw new NotFoundHttpException('Article was not found.');
192 192
     }
193 193
 
194 194
     return $article;
195
-  }
195
+    }
196 196
 }
Please login to merge, or discard this patch.