Completed
Push — SWP-2317 ( a75896...605d9f )
by
unknown
47s
created
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,32 +102,32 @@  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
     $article = $this->entityManager->getRepository('SWP\Bundle\ContentBundle\Model\Article')
127 127
         ->findOneBy(['code' => $code]);
128 128
 
129 129
     if (null === $article) {
130
-      throw new NotFoundHttpException('Article was not found');
130
+        throw new NotFoundHttpException('Article was not found');
131 131
     }
132 132
 
133 133
     $article->setStatus('new');
@@ -148,12 +148,12 @@  discard block
 block discarded – undo
148 148
     }
149 149
 
150 150
     return new SingleResourceResponse($article);
151
-  }
151
+    }
152 152
 
153
-  /**
154
-   * @Route("/api/{version}/content/articles/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_update_articles", requirements={"id"=".+"})
155
-   */
156
-  public function updateAction(Request $request, $id): SingleResourceResponseInterface {
153
+    /**
154
+     * @Route("/api/{version}/content/articles/{id}", methods={"PATCH"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_update_articles", requirements={"id"=".+"})
155
+     */
156
+    public function updateAction(Request $request, $id): SingleResourceResponseInterface {
157 157
     $objectManager = $this->entityManager;
158 158
     $article = $this->findOr404($id);
159 159
     $originalArticleStatus = $article->getStatus();
@@ -162,32 +162,32 @@  discard block
 block discarded – undo
162 162
 
163 163
     $form->handleRequest($request);
164 164
     if ($form->isSubmitted() && $form->isValid()) {
165
-      $this->articleService->reactOnStatusChange($originalArticleStatus, $article);
166
-      $objectManager->flush();
167
-      $objectManager->refresh($article);
165
+        $this->articleService->reactOnStatusChange($originalArticleStatus, $article);
166
+        $objectManager->flush();
167
+        $objectManager->refresh($article);
168 168
 
169
-      return new SingleResourceResponse($article);
169
+        return new SingleResourceResponse($article);
170 170
     }
171 171
 
172 172
     return new SingleResourceResponse($form, new ResponseContext(500));
173
-  }
173
+    }
174 174
 
175
-  /**
176
-   * @Route("/api/{version}/content/articles/{id}", methods={"DELETE"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_delete_articles", requirements={"id"=".+"})
177
-   */
178
-  public function deleteAction($id): SingleResourceResponseInterface {
175
+    /**
176
+     * @Route("/api/{version}/content/articles/{id}", methods={"DELETE"}, options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_content_delete_articles", requirements={"id"=".+"})
177
+     */
178
+    public function deleteAction($id): SingleResourceResponseInterface {
179 179
     $objectManager = $this->entityManager;
180 180
     $objectManager->remove($this->findOr404($id));
181 181
     $objectManager->flush();
182 182
 
183 183
     return new SingleResourceResponse(null, new ResponseContext(204));
184
-  }
184
+    }
185 185
 
186
-  private function findOr404($id) {
186
+    private function findOr404($id) {
187 187
     if (null === $article = $this->articleProvider->getOneById($id)) {
188
-      throw new NotFoundHttpException('Article was not found.');
188
+        throw new NotFoundHttpException('Article was not found.');
189 189
     }
190 190
 
191 191
     return $article;
192
-  }
192
+    }
193 193
 }
Please login to merge, or discard this patch.