| Conditions | 11 |
| Paths | 13 |
| Total Lines | 67 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 31 | public function completeAction(Request $request) |
||
| 32 | { |
||
| 33 | $configuration = $this->requestConfigurationFactory->create($this->metadata, $request); |
||
| 34 | |||
| 35 | $this->isGrantedOr403($configuration, ResourceActions::UPDATE); |
||
| 36 | $order = $this->findOr404($configuration); |
||
| 37 | |||
| 38 | $form = $this->resourceFormFactory->create($configuration, $order); |
||
| 39 | |||
| 40 | if (in_array($request->getMethod(), ['POST', 'PUT', 'PATCH'], true) && $form->handleRequest($request)->isValid()) { |
||
| 41 | $order = $form->getData(); |
||
| 42 | |||
| 43 | /** @var ResourceControllerEvent $event */ |
||
| 44 | $event = $this->eventDispatcher->dispatchPreEvent(ResourceActions::UPDATE, $configuration, $order); |
||
| 45 | |||
| 46 | if ($event->isStopped() && !$configuration->isHtmlRequest()) { |
||
| 47 | throw new HttpException($event->getErrorCode(), $event->getMessage()); |
||
| 48 | } |
||
| 49 | if ($event->isStopped()) { |
||
| 50 | $this->flashHelper->addFlashFromEvent($configuration, $event); |
||
| 51 | |||
| 52 | if ($event->hasResponse()) { |
||
| 53 | return $event->getResponse(); |
||
| 54 | } |
||
| 55 | |||
| 56 | return $this->redirectHandler->redirectToResource($configuration, $order); |
||
| 57 | } |
||
| 58 | |||
| 59 | try { |
||
| 60 | if ($configuration->hasStateMachine()) { |
||
| 61 | $this->stateMachine->apply($configuration, $order); |
||
| 62 | } |
||
| 63 | |||
| 64 | $this->manager->flush(); |
||
| 65 | } catch (OptimisticLockException $exception) { |
||
| 66 | $this->addFlash('error', 'sylius.checkout.complete_error'); |
||
| 67 | |||
| 68 | return $this->redirectHandler->redirectToRoute($configuration, 'sylius_shop_checkout_complete'); |
||
| 69 | } |
||
| 70 | |||
| 71 | $this->eventDispatcher->dispatchPostEvent(ResourceActions::UPDATE, $configuration, $order); |
||
| 72 | |||
| 73 | if (!$configuration->isHtmlRequest()) { |
||
| 74 | return $this->viewHandler->handle($configuration, View::create(null, Response::HTTP_NO_CONTENT)); |
||
| 75 | } |
||
| 76 | |||
| 77 | $this->flashHelper->addSuccessFlash($configuration, ResourceActions::UPDATE, $order); |
||
| 78 | |||
| 79 | return $this->redirectHandler->redirectToResource($configuration, $order); |
||
| 80 | } |
||
| 81 | |||
| 82 | if (!$configuration->isHtmlRequest()) { |
||
| 83 | return $this->viewHandler->handle($configuration, View::create($form, Response::HTTP_BAD_REQUEST)); |
||
| 84 | } |
||
| 85 | |||
| 86 | $view = View::create() |
||
| 87 | ->setData([ |
||
| 88 | 'configuration' => $configuration, |
||
| 89 | 'metadata' => $this->metadata, |
||
| 90 | 'order' => $order, |
||
| 91 | 'form' => $form->createView(), |
||
| 92 | ]) |
||
| 93 | ->setTemplate($configuration->getTemplate(ResourceActions::UPDATE . '.html')) |
||
| 94 | ; |
||
| 95 | |||
| 96 | return $this->viewHandler->handle($configuration, $view); |
||
| 97 | } |
||
| 98 | |||
| 134 |