Conditions | 12 |
Paths | 81 |
Total Lines | 61 |
Code Lines | 39 |
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 |
||
38 | public function execute($request): void |
||
39 | { |
||
40 | RequestNotSupportedException::assertSupports($this, $request); |
||
41 | |||
42 | /** @var PaymentInterface $payment */ |
||
43 | $payment = $request->getModel(); |
||
44 | |||
45 | $details = $payment->getDetails(); |
||
46 | |||
47 | if (!isset($details['orderToken'])) { |
||
48 | $request->markNew(); |
||
49 | |||
50 | return; |
||
51 | } |
||
52 | |||
53 | $this->gateway->execute($httpRequest = new GetHttpRequest()); |
||
54 | |||
55 | try { |
||
56 | if (isset($details['orderId'])) { |
||
57 | $order = $this->quadPayApiClient->getOrderById($details['orderId']); |
||
58 | } else { |
||
59 | $order = $this->quadPayApiClient->getOrderByToken($details['orderToken']); |
||
60 | } |
||
61 | |||
62 | $details['orderId'] = $order['orderId']; |
||
63 | $details['orderStatus'] = strtolower($order['orderStatus']); |
||
64 | } catch (ClientException $clientException) { |
||
65 | if ( |
||
66 | (Response::HTTP_NOT_FOUND === $clientException->getCode() && |
||
67 | isset($httpRequest->query['status']) && QuadPayApiClientInterface::STATUS_ABANDONED === $httpRequest->query['status']) || |
||
68 | QuadPayApiClientInterface::STATUS_ABANDONED === $details['orderStatus'] |
||
69 | ) { |
||
70 | $details['orderStatus'] = QuadPayApiClientInterface::STATUS_ABANDONED; |
||
71 | } else { |
||
72 | $details['orderStatus'] = QuadPayApiClientInterface::STATUS_DECLINED; |
||
73 | } |
||
74 | } |
||
75 | |||
76 | $payment->setDetails($details); |
||
77 | |||
78 | switch ($details['orderStatus']) { |
||
79 | case QuadPayApiClientInterface::STATUS_CREATED: |
||
80 | $request->markPending(); |
||
81 | |||
82 | break; |
||
83 | case QuadPayApiClientInterface::STATUS_ABANDONED: |
||
84 | $request->markCanceled(); |
||
85 | |||
86 | break; |
||
87 | case QuadPayApiClientInterface::STATUS_DECLINED: |
||
88 | $request->markFailed(); |
||
89 | |||
90 | break; |
||
91 | case QuadPayApiClientInterface::STATUS_APPROVED: |
||
92 | $request->markCaptured(); |
||
93 | |||
94 | break; |
||
95 | default: |
||
96 | $request->markUnknown(); |
||
97 | |||
98 | break; |
||
99 | } |
||
110 |