| Conditions | 13 | 
| Paths | 150 | 
| Total Lines | 64 | 
| Code Lines | 42 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 4 | ||
| Bugs | 1 | Features | 1 | 
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 getData() | ||
| 23 |     { | ||
| 24 |         $this->validate('privateKey', 'transactionId', 'amount'); | ||
| 25 | |||
| 26 | $data = ['success' => false]; | ||
| 27 | |||
| 28 | $parameters = [ | ||
| 29 | 'amount' => $this->getAmount() * 100, | ||
| 30 | ]; | ||
| 31 | |||
| 32 | //optionals | ||
| 33 |         $currency = $this->getParameter('currency'); | ||
| 34 |         if (is_string($currency) && strlen($currency) === 3) { | ||
| 35 | $parameters['currency'] = $currency; | ||
| 36 | } | ||
| 37 |         $descriptor = $this->getParameter('descriptor'); | ||
| 38 |         if (is_string($descriptor)) { | ||
| 39 |             if (Helper::validateDescriptor($descriptor)) { | ||
| 40 |                 throw new \Omnipay\Common\Exception\InvalidRequestException("The descriptor does not conform to requirements."); | ||
| 41 | } | ||
| 42 | $parameters['descriptor'] = $descriptor; | ||
| 43 | } | ||
| 44 | |||
| 45 | |||
| 46 |         try { | ||
| 47 | $transactions = $this->getApi()->transactions(); | ||
| 48 | $transaction = $transactions->capture( | ||
| 49 | $this->getTransactionId(), | ||
| 50 | $parameters | ||
| 51 | ); | ||
| 52 |             if (is_array($transaction)) { | ||
|  | |||
| 53 | $data['transaction'] = $transaction; | ||
| 54 | $data['success'] = true; | ||
| 55 | } | ||
| 56 |         } catch (\Paylike\Exception\NotFound $e) { | ||
| 57 | //The transaction was not found | ||
| 58 | $data['exception_class'] = "\Paylike\Exception\NotFound"; | ||
| 59 | $data['message'] = "The transaction was not found"; | ||
| 60 |         } catch (\Paylike\Exception\InvalidRequest $e) { | ||
| 61 | // Bad (invalid) request - see $e->getJsonBody() for the error | ||
| 62 | $data['exception_class'] = "\Paylike\Exception\InvalidRequest"; | ||
| 63 | $data['message'] = "Bad (invalid) request - " . substr(json_encode($e->getJsonBody()), 0, 250); | ||
| 64 |         } catch (\Paylike\Exception\Forbidden $e) { | ||
| 65 | // You are correctly authenticated but do not have access. | ||
| 66 | $data['exception_class'] = "\Paylike\Exception\Forbidden"; | ||
| 67 | $data['message'] = "You are correctly authenticated but do not have access."; | ||
| 68 |         } catch (\Paylike\Exception\Unauthorized $e) { | ||
| 69 | // You need to provide credentials (an app's API key) | ||
| 70 | $data['exception_class'] = "\Paylike\Exception\Unauthorized"; | ||
| 71 | $data['message'] = "You need to provide credentials (an app's API key)"; | ||
| 72 |         } catch (\Paylike\Exception\Conflict $e) { | ||
| 73 | // Everything you submitted was fine at the time of validation, but something changed in the meantime and came into conflict with this (e.g. double-capture). | ||
| 74 | $data['exception_class'] = "\Paylike\Exception\Conflict"; | ||
| 75 | $data['message'] = "Everything you submitted was fine at the time of validation, but something changed in the meantime and came into conflict with this (e.g. double-capture)"; | ||
| 76 |         } catch (\Paylike\Exception\ApiConnection $e) { | ||
| 77 | // Network error on connecting via cURL | ||
| 78 | $data['exception_class'] = "\Paylike\Exception\ApiConnection"; | ||
| 79 | $data['message'] = "Network error on connecting via cURL"; | ||
| 80 |         } catch (\Paylike\Exception\ApiException $e) { | ||
| 81 | $data['exception_class'] = "\Paylike\Exception\ApiException"; | ||
| 82 | $data['message'] = "Api Error:" . $e->getMessage(); | ||
| 83 | } | ||
| 84 | |||
| 85 | return $data; | ||
| 86 | } | ||
| 88 |