Conditions | 4 |
Paths | 4 |
Total Lines | 68 |
Code Lines | 54 |
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); |
||
73 | public function send(ApiClient $apiClient): PaymentButtonResponse |
||
74 | { |
||
75 | $requestData = [ |
||
76 | 'merchantId' => $this->merchantId, |
||
77 | 'orderNo' => $this->orderId, |
||
78 | 'clientIp' => $this->clientIp, |
||
79 | 'totalAmount' => $this->totalPrice->getAmount(), |
||
80 | 'currency' => $this->totalPrice->getCurrency()->getValue(), |
||
81 | 'returnUrl' => $this->returnUrl, |
||
82 | 'returnMethod' => $this->returnMethod->getValue(), |
||
83 | 'brand' => $this->brand->getValue(), |
||
84 | 'language' => $this->language->getValue(), |
||
85 | ]; |
||
86 | |||
87 | if ($this->merchantData !== null) { |
||
88 | $requestData['merchantData'] = $this->merchantData; |
||
89 | } |
||
90 | |||
91 | $response = $apiClient->post( |
||
92 | 'button/init', |
||
93 | $requestData, |
||
94 | new SignatureDataFormatter([ |
||
95 | 'merchantId' => null, |
||
96 | 'orderNo' => null, |
||
97 | 'dttm' => null, |
||
98 | 'clientIp' => null, |
||
99 | 'totalAmount' => null, |
||
100 | 'currency' => null, |
||
101 | 'returnUrl' => null, |
||
102 | 'returnMethod' => null, |
||
103 | 'brand' => null, |
||
104 | 'merchantData' => null, |
||
105 | 'language' => null, |
||
106 | ]), |
||
107 | new SignatureDataFormatter([ |
||
108 | 'payId' => null, |
||
109 | 'dttm' => null, |
||
110 | 'resultCode' => null, |
||
111 | 'resultMessage' => null, |
||
112 | 'paymentStatus' => null, |
||
113 | 'redirect' => [ |
||
114 | 'method' => null, |
||
115 | 'url' => null, |
||
116 | 'params' => null, |
||
117 | ], |
||
118 | ]) |
||
119 | ); |
||
120 | |||
121 | $data = $response->getData(); |
||
122 | |||
123 | $redirectUrl = null; |
||
124 | $redirectMethod = null; |
||
125 | $redirectParams = []; |
||
126 | if (isset($data['redirect'])) { |
||
127 | $redirectUrl = $data['redirect']['url']; |
||
128 | $redirectMethod = HttpMethod::get($data['redirect']['method']); |
||
129 | $redirectParams = $data['redirect']['params'] ?? null; |
||
130 | } |
||
131 | |||
132 | return new PaymentButtonResponse( |
||
133 | $data['payId'], |
||
134 | DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']), |
||
|
|||
135 | ResultCode::get($data['resultCode']), |
||
136 | $data['resultMessage'], |
||
137 | isset($data['paymentStatus']) ? PaymentStatus::get($data['paymentStatus']) : null, |
||
138 | $redirectMethod, |
||
139 | $redirectUrl, |
||
140 | $redirectParams |
||
141 | ); |
||
145 |