| Conditions | 12 |
| Paths | 21 |
| Total Lines | 40 |
| 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 | /** @var ArrayObject $details */ |
||
| 28 | $details = ArrayObject::ensureArrayObject($request->getModel()); |
||
| 29 | |||
| 30 | if (empty($details) || !isset($details['preference'])) { |
||
| 31 | $request->markNew(); |
||
| 32 | |||
| 33 | return; |
||
| 34 | } |
||
| 35 | |||
| 36 | $status = null; |
||
| 37 | |||
| 38 | $this->gateway->execute($httpRequest = new GetHttpRequest()); |
||
| 39 | |||
| 40 | if (isset($httpRequest->query['collection_status'])) { |
||
| 41 | $status = $httpRequest->query['collection_status']; |
||
| 42 | } |
||
| 43 | |||
| 44 | if (!$status && isset($details['payment']) && isset($details['payment']['status'])) { |
||
| 45 | $status = $details['payment']['status']; |
||
| 46 | } |
||
| 47 | |||
| 48 | if (!$status) { |
||
| 49 | $request->markNew(); |
||
| 50 | |||
| 51 | return; |
||
| 52 | } |
||
| 53 | |||
| 54 | if ('approved' === $status) { |
||
| 55 | $request->markCaptured(); |
||
| 56 | } elseif ('rejected' === $status) { |
||
| 57 | $request->markFailed(); |
||
| 58 | } elseif ('pending' === $status || 'in_process' === $status) { |
||
| 59 | $request->markPending(); |
||
| 60 | } else { |
||
| 61 | $request->markCanceled(); |
||
| 62 | } |
||
| 76 |