Conditions | 12 |
Paths | 21 |
Total Lines | 39 |
Code Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 1 | 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 |
||
22 | public function execute($request): void |
||
23 | { |
||
24 | /** @var GetStatusInterface $request */ |
||
25 | RequestNotSupportedException::assertSupports($this, $request); |
||
26 | |||
27 | $details = ArrayObject::ensureArrayObject($request->getModel()); |
||
28 | |||
29 | if (count($details) === 0 || !isset($details['preference'])) { |
||
30 | $request->markNew(); |
||
31 | |||
32 | return; |
||
33 | } |
||
34 | |||
35 | $status = null; |
||
36 | |||
37 | $this->gateway->execute($httpRequest = new GetHttpRequest()); |
||
38 | |||
39 | if (isset($httpRequest->query['collection_status'])) { |
||
40 | $status = $httpRequest->query['collection_status']; |
||
41 | } |
||
42 | |||
43 | if (!$status && isset($details['payment']) && isset($details['payment']['status'])) { |
||
44 | $status = $details['payment']['status']; |
||
45 | } |
||
46 | |||
47 | if (!$status) { |
||
48 | $request->markNew(); |
||
49 | |||
50 | return; |
||
51 | } |
||
52 | |||
53 | if ('approved' === $status) { |
||
54 | $request->markCaptured(); |
||
55 | } elseif ('rejected' === $status) { |
||
56 | $request->markFailed(); |
||
57 | } elseif ('pending' === $status || 'in_process' === $status) { |
||
58 | $request->markPending(); |
||
59 | } else { |
||
60 | $request->markCanceled(); |
||
61 | } |
||
75 |