| Conditions | 8 |
| Paths | 32 |
| Total Lines | 101 |
| Code Lines | 74 |
| 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); |
||
| 140 | public function send(ApiClient $apiClient): PaymentResponse |
||
| 141 | { |
||
| 142 | $amount = $this->cart->getCurrentAmount(); |
||
| 143 | |||
| 144 | $requestData = [ |
||
| 145 | 'merchantId' => $this->merchantId, |
||
| 146 | 'orderNo' => $this->orderId, |
||
| 147 | 'payOperation' => $this->payOperation->getValue(), |
||
| 148 | 'payMethod' => $this->payMethod->getValue(), |
||
| 149 | 'totalAmount' => $amount->getValue(), |
||
| 150 | 'currency' => $amount->getCurrency()->getValue(), |
||
| 151 | 'closePayment' => $this->closePayment, |
||
| 152 | 'returnUrl' => $this->returnUrl, |
||
| 153 | 'returnMethod' => $this->returnMethod->getValue(), |
||
| 154 | 'cart' => array_map(function (CartItem $cartItem) { |
||
| 155 | $cartItemValues = [ |
||
| 156 | 'name' => $cartItem->getName(), |
||
| 157 | 'quantity' => $cartItem->getQuantity(), |
||
| 158 | 'amount' => $cartItem->getAmount(), |
||
| 159 | ]; |
||
| 160 | |||
| 161 | if ($cartItem->getDescription() !== null) { |
||
| 162 | $cartItemValues['description'] = $cartItem->getDescription(); |
||
| 163 | } |
||
| 164 | |||
| 165 | return $cartItemValues; |
||
| 166 | |||
| 167 | }, $this->cart->getItems()), |
||
| 168 | 'description' => $this->description, |
||
| 169 | 'language' => $this->language->getValue(), |
||
| 170 | ]; |
||
| 171 | |||
| 172 | if ($this->merchantData !== null) { |
||
| 173 | $requestData['merchantData'] = base64_encode($this->merchantData); |
||
| 174 | } |
||
| 175 | |||
| 176 | if ($this->customerId !== null) { |
||
| 177 | $requestData['customerId'] = $this->customerId; |
||
| 178 | } |
||
| 179 | |||
| 180 | if ($this->ttlSec !== null) { |
||
| 181 | $requestData['ttlSec'] = $this->ttlSec; |
||
| 182 | } |
||
| 183 | |||
| 184 | if ($this->logoVersion !== null) { |
||
| 185 | $requestData['logoVersion'] = $this->logoVersion; |
||
| 186 | } |
||
| 187 | |||
| 188 | if ($this->colorSchemeVersion !== null) { |
||
| 189 | $requestData['colorSchemeVersion'] = $this->colorSchemeVersion; |
||
| 190 | } |
||
| 191 | |||
| 192 | $response = $apiClient->post( |
||
| 193 | 'payment/init', |
||
| 194 | $requestData, |
||
| 195 | new SignatureDataFormatter([ |
||
| 196 | 'merchantId' => null, |
||
| 197 | 'orderNo' => null, |
||
| 198 | 'dttm' => null, |
||
| 199 | 'payOperation' => null, |
||
| 200 | 'payMethod' => null, |
||
| 201 | 'totalAmount' => null, |
||
| 202 | 'currency' => null, |
||
| 203 | 'closePayment' => null, |
||
| 204 | 'returnUrl' => null, |
||
| 205 | 'returnMethod' => null, |
||
| 206 | 'cart' => [ |
||
| 207 | 'name' => null, |
||
| 208 | 'quantity' => null, |
||
| 209 | 'amount' => null, |
||
| 210 | 'description' => null, |
||
| 211 | ], |
||
| 212 | 'description' => null, |
||
| 213 | 'merchantData' => null, |
||
| 214 | 'customerId' => null, |
||
| 215 | 'language' => null, |
||
| 216 | 'ttlSec' => null, |
||
| 217 | 'logoVersion' => null, |
||
| 218 | 'colorSchemeVersion' => null, |
||
| 219 | ]), |
||
| 220 | new SignatureDataFormatter([ |
||
| 221 | 'payId' => null, |
||
| 222 | 'dttm' => null, |
||
| 223 | 'resultCode' => null, |
||
| 224 | 'resultMessage' => null, |
||
| 225 | 'paymentStatus' => null, |
||
| 226 | 'authCode' => null, |
||
| 227 | ]) |
||
| 228 | ); |
||
| 229 | |||
| 230 | $data = $response->getData(); |
||
| 231 | |||
| 232 | return new PaymentResponse( |
||
| 233 | $data['payId'], |
||
| 234 | DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']), |
||
| 235 | new ResultCode($data['resultCode']), |
||
| 236 | $data['resultMessage'], |
||
| 237 | isset($data['paymentStatus']) ? new PaymentStatus($data['paymentStatus']) : null, |
||
| 238 | $data['authCode'] ?? null |
||
| 239 | ); |
||
| 240 | } |
||
| 241 | |||
| 243 |