Conditions | 9 |
Paths | 12 |
Total Lines | 69 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
27 | public function updateAppleOrderAction(Request $request): Response |
||
28 | { |
||
29 | $configuration = $this->requestConfigurationFactory->create($this->metadata, $request); |
||
30 | |||
31 | $this->isGrantedOr403($configuration, ResourceActions::UPDATE); |
||
32 | $resource = $this->findOr404($configuration); |
||
33 | |||
34 | /** @var ResourceControllerEvent $event */ |
||
35 | $event = $this->eventDispatcher->dispatchPreEvent(ResourceActions::UPDATE, $configuration, $resource); |
||
36 | |||
37 | if ($event->isStopped() && !$configuration->isHtmlRequest()) { |
||
38 | throw new HttpException($event->getErrorCode(), $event->getMessage()); |
||
39 | } |
||
40 | |||
41 | if ($event->isStopped()) { |
||
42 | $eventResponse = $event->getResponse(); |
||
43 | if (!empty($eventResponse)) { |
||
44 | return $eventResponse; |
||
45 | } |
||
46 | |||
47 | return new JsonResponse([], Response::HTTP_BAD_REQUEST); |
||
48 | } |
||
49 | |||
50 | try { |
||
51 | $this->getApplePayProviderService()->provideOrder($this->getCurrentCart(), $request); |
||
52 | |||
53 | /** @var PaymentInterface $payment */ |
||
54 | $payment = $this->getCurrentCart()->getLastPayment(); |
||
|
|||
55 | |||
56 | if ($payment->getState() !== PaymentInterface::STATE_COMPLETED) { |
||
57 | $response = [ |
||
58 | 'status' => 1, |
||
59 | 'errors' => 'Payment not created', |
||
60 | ]; |
||
61 | |||
62 | return new JsonResponse($response, Response::HTTP_BAD_REQUEST); |
||
63 | } |
||
64 | |||
65 | $this->resourceUpdateHandler->handle($resource, $configuration, $this->manager); |
||
66 | } catch (UpdateHandlingException $exception) { |
||
67 | return new JsonResponse([], Response::HTTP_BAD_REQUEST); |
||
68 | } |
||
69 | |||
70 | $postEvent = $this->eventDispatcher->dispatchPostEvent(ResourceActions::UPDATE, $configuration, $resource); |
||
71 | |||
72 | $postEventResponse = $postEvent->getResponse(); |
||
73 | |||
74 | if (!empty($postEventResponse)) { |
||
75 | return $postEventResponse; |
||
76 | } |
||
77 | |||
78 | $initializeEvent = $this->eventDispatcher->dispatchInitializeEvent(ResourceActions::UPDATE, $configuration, $resource); |
||
79 | |||
80 | $initializeEventResponse = $initializeEvent->getResponse(); |
||
81 | |||
82 | if (!empty($initializeEventResponse)) { |
||
83 | return $initializeEventResponse; |
||
84 | } |
||
85 | |||
86 | $redirect = $this->redirectToRoute('sylius_shop_order_thank_you'); |
||
87 | $dataResponse['returnUrl'] = $redirect->getTargetUrl(); |
||
88 | $dataResponse['responseToApple'] = ['status' => 0]; |
||
89 | |||
90 | $response = [ |
||
91 | 'success' => true, |
||
92 | 'data' => $dataResponse, |
||
93 | ]; |
||
94 | |||
95 | return new JsonResponse($response, Response::HTTP_OK); |
||
96 | } |
||
103 |