Conditions | 15 |
Paths | 31 |
Total Lines | 56 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
30 | public function execute($request): void |
||
31 | { |
||
32 | RequestNotSupportedException::assertSupports($this, $request); |
||
33 | |||
34 | /** @var PaymentInterface $payment */ |
||
35 | $payment = $request->getModel(); |
||
36 | |||
37 | $details = $payment->getDetails(); |
||
38 | |||
39 | if (!isset($details['status']) || !isset($details['orderId'])) { |
||
40 | $request->markNew(); |
||
41 | |||
42 | return; |
||
43 | } |
||
44 | |||
45 | $this->gateway->execute($httpRequest = new GetHttpRequest()); |
||
46 | |||
47 | if (isset($httpRequest->query['type']) && MultiSafepayApiClientInterface::STATUS_CANCEL === $httpRequest->query['type']) { |
||
48 | $details['status'] = MultiSafepayApiClientInterface::STATUS_CANCELED; |
||
49 | } elseif (MultiSafepayApiClientInterface::STATUS_CANCELED !== $details['status']) { |
||
50 | $order = $this->multiSafepayApiClient->getOrderById($details['orderId']); |
||
51 | |||
52 | $details['status'] = $order->status; |
||
53 | } |
||
54 | |||
55 | $payment->setDetails($details); |
||
56 | |||
57 | switch ($details['status']) { |
||
58 | case MultiSafepayApiClientInterface::STATUS_CANCELED: |
||
59 | case MultiSafepayApiClientInterface::STATUS_VOID: |
||
60 | $request->markCanceled(); |
||
61 | |||
62 | break; |
||
63 | case MultiSafepayApiClientInterface::STATUS_COMPLETED: |
||
64 | $request->markCaptured(); |
||
65 | |||
66 | break; |
||
67 | case MultiSafepayApiClientInterface::STATUS_INITIALIZED: |
||
68 | case MultiSafepayApiClientInterface::STATUS_UNCLEARED: |
||
69 | case MultiSafepayApiClientInterface::STATUS_RESERVED: |
||
70 | $request->markPending(); |
||
71 | |||
72 | break; |
||
73 | case MultiSafepayApiClientInterface::STATUS_DECLINED: |
||
74 | case MultiSafepayApiClientInterface::STATUS_EXPIRED: |
||
75 | $request->markFailed(); |
||
76 | |||
77 | break; |
||
78 | case MultiSafepayApiClientInterface::STATUS_REFUNDED: |
||
79 | $request->markRefunded(); |
||
80 | |||
81 | break; |
||
82 | default: |
||
83 | $request->markUnknown(); |
||
84 | |||
85 | break; |
||
86 | } |
||
97 |