| Conditions | 3 |
| Paths | 12 |
| Total Lines | 84 |
| Code Lines | 59 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 23 | public function directTokenization(string $paymentNonce, string $deviceData): ?array |
||
| 24 | { |
||
| 25 | try { |
||
| 26 | $ch = curl_init(); |
||
| 27 | curl_setopt($ch, CURLOPT_URL, $this->ENDPOINT); |
||
| 28 | curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type:application/json']); |
||
| 29 | curl_setopt( |
||
| 30 | $ch, |
||
| 31 | CURLOPT_USERPWD, |
||
| 32 | $this->gateway->config->getPublicKey() . ':' . $this->gateway->config->getPrivateKey() |
||
| 33 | ); |
||
| 34 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); |
||
| 35 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([ |
||
| 36 | 'debug_transformations' => true, |
||
| 37 | 'name' => 'default', |
||
| 38 | 'merchant_id' => $this->gateway->config->getMerchantId(), |
||
| 39 | 'payment_method_nonce' => $paymentNonce, |
||
| 40 | 'device_data' => $deviceData, |
||
| 41 | 'method' => 'POST', |
||
| 42 | 'data' => [ |
||
| 43 | 'card-id' => 'custom_card_id_1', |
||
| 44 | 'open-id-token' => sha1(time()), |
||
| 45 | ], |
||
| 46 | 'url' => 'https://test.com', |
||
| 47 | 'config' => [ |
||
| 48 | 'name' => 'default', |
||
| 49 | 'url' => '^https://test.com', |
||
| 50 | 'methods' => ['POST'], |
||
| 51 | 'types' => ['NetworkTokenizedCard'], |
||
| 52 | 'request_format' => [ |
||
| 53 | 'body' => 'json' |
||
| 54 | ], |
||
| 55 | 'transformations' => [ |
||
| 56 | [ |
||
| 57 | 'path' => '/body/card/pan', |
||
| 58 | 'value' => '$number' |
||
| 59 | ], |
||
| 60 | [ |
||
| 61 | 'path' => '/body/card/card-cvv', |
||
| 62 | 'value' => '$cvv' |
||
| 63 | ], |
||
| 64 | [ |
||
| 65 | 'path' => '/body/card/expiration-month', |
||
| 66 | 'value' => '$expiration_month' |
||
| 67 | ], |
||
| 68 | [ |
||
| 69 | 'path' => '/body/card/expiration-year', |
||
| 70 | 'value' => '$expiration_year' |
||
| 71 | ], |
||
| 72 | [ |
||
| 73 | 'path' => '/body/custom-fields/card-id', |
||
| 74 | 'value' => '$card-id' |
||
| 75 | ], |
||
| 76 | [ |
||
| 77 | 'path' => '/header/Authorization', |
||
| 78 | 'value' => '$open-id-token' |
||
| 79 | ] |
||
| 80 | ] |
||
| 81 | |||
| 82 | ] |
||
| 83 | ], true)); |
||
|
|
|||
| 84 | |||
| 85 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
||
| 86 | curl_setopt($ch, CURLOPT_HEADERFUNCTION, function ($curl, $header) use (&$headers) { |
||
| 87 | $len = strlen($header); |
||
| 88 | $header = explode(':', $header, 2); |
||
| 89 | if (count($header) < 2) { |
||
| 90 | return $len; |
||
| 91 | } |
||
| 92 | $headers[(trim($header[0]))] = trim($header[1]); |
||
| 93 | return $len; |
||
| 94 | }); |
||
| 95 | $result = curl_exec($ch); |
||
| 96 | $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
||
| 97 | |||
| 98 | curl_close($ch); |
||
| 99 | } catch (Exception $e) { |
||
| 100 | $this->logger->error('Error on ForwardAPI::'.$this->ENDPOINT.' = ' . $e->getMessage()); |
||
| 101 | return null; |
||
| 102 | } |
||
| 103 | return ([ |
||
| 104 | 'headers' => (object) $headers, |
||
| 105 | 'body' => (object) json_decode($result), |
||
| 106 | 'statusCode' => $statusCode |
||
| 107 | ]); |
||
| 110 |