| Conditions | 4 |
| Paths | 4 |
| Total Lines | 51 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 declare(strict_types = 1); |
||
| 66 | public function send(ApiClient $apiClient): PaymentResponse |
||
| 67 | { |
||
| 68 | $requestData = [ |
||
| 69 | 'merchantId' => $this->merchantId, |
||
| 70 | 'orderNo' => $this->orderId, |
||
| 71 | 'totalAmount' => $this->totalPrice->getAmount(), |
||
| 72 | 'currency' => $this->totalPrice->getCurrency()->getValue(), |
||
| 73 | 'closePayment' => $this->closePayment, |
||
| 74 | 'clientIp' => $this->clientIp, |
||
| 75 | ]; |
||
| 76 | |||
| 77 | if ($this->merchantData !== null) { |
||
| 78 | $requestData['merchantData'] = base64_encode($this->merchantData); |
||
| 79 | } |
||
| 80 | |||
| 81 | if ($this->ttlSec !== null) { |
||
| 82 | $requestData['ttlSec'] = $this->ttlSec; |
||
| 83 | } |
||
| 84 | |||
| 85 | $response = $apiClient->post( |
||
| 86 | 'applepay/init', |
||
| 87 | $requestData, |
||
| 88 | new SignatureDataFormatter([ |
||
| 89 | 'merchantId' => null, |
||
| 90 | 'orderNo' => null, |
||
| 91 | 'dttm' => null, |
||
| 92 | 'clientIp' => null, |
||
| 93 | 'totalAmount' => null, |
||
| 94 | 'currency' => null, |
||
| 95 | 'closePayment' => null, |
||
| 96 | 'merchantData' => null, |
||
| 97 | 'ttlSec' => null, |
||
| 98 | ]), |
||
| 99 | new SignatureDataFormatter([ |
||
| 100 | 'payId' => null, |
||
| 101 | 'dttm' => null, |
||
| 102 | 'resultCode' => null, |
||
| 103 | 'resultMessage' => null, |
||
| 104 | 'paymentStatus' => null, |
||
| 105 | ]) |
||
| 106 | ); |
||
| 107 | |||
| 108 | $data = $response->getData(); |
||
| 109 | $responseDateTime = DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']); |
||
| 110 | |||
| 111 | return new PaymentResponse( |
||
| 112 | $data['payId'], |
||
| 113 | $responseDateTime, |
||
|
|
|||
| 114 | ResultCode::get($data['resultCode']), |
||
| 115 | $data['resultMessage'], |
||
| 116 | isset($data['paymentStatus']) ? PaymentStatus::get($data['paymentStatus']) : null |
||
| 117 | ); |
||
| 121 |