Conditions | 6 |
Paths | 8 |
Total Lines | 87 |
Code Lines | 65 |
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); |
||
116 | public function send(ApiClient $apiClient): PaymentResponse |
||
117 | { |
||
118 | $requestData = [ |
||
119 | 'merchantId' => $this->merchantId, |
||
120 | 'orderNo' => $this->orderId, |
||
121 | 'payOperation' => $this->payOperation->getValue(), |
||
122 | 'payMethod' => $this->payMethod->getValue(), |
||
123 | 'totalAmount' => $this->cart->countTotalAmount(), |
||
124 | 'currency' => $this->cart->getCurrency()->getValue(), |
||
125 | 'closePayment' => $this->closePayment, |
||
126 | 'returnUrl' => $this->returnUrl, |
||
127 | 'returnMethod' => $this->returnMethod->getValue(), |
||
128 | 'cart' => array_map(function (CartItem $cartItem) { |
||
129 | $cartItemValues = [ |
||
130 | 'name' => $cartItem->getName(), |
||
131 | 'quantity' => $cartItem->getQuantity(), |
||
132 | 'amount' => $cartItem->getAmount(), |
||
133 | ]; |
||
134 | |||
135 | if ($cartItem->getDescription() !== null) { |
||
136 | $cartItemValues['description'] = $cartItem->getDescription(); |
||
137 | } |
||
138 | |||
139 | return $cartItemValues; |
||
140 | |||
141 | }, $this->cart->getItems()), |
||
142 | 'description' => $this->description, |
||
143 | ]; |
||
144 | |||
145 | if ($this->merchantData !== null) { |
||
146 | $requestData['merchantData'] = base64_encode($this->merchantData); |
||
147 | } |
||
148 | |||
149 | if ($this->customerId !== null) { |
||
150 | $requestData['customerId'] = $this->customerId; |
||
151 | } |
||
152 | |||
153 | if ($this->language !== null) { |
||
154 | $requestData['language'] = $this->language->getValue(); |
||
155 | } |
||
156 | |||
157 | $response = $apiClient->post( |
||
158 | 'payment/init', |
||
159 | $requestData, |
||
160 | new SignatureDataFormatter([ |
||
161 | 'merchantId' => null, |
||
162 | 'orderNo' => null, |
||
163 | 'dttm' => null, |
||
164 | 'payOperation' => null, |
||
165 | 'payMethod' => null, |
||
166 | 'totalAmount' => null, |
||
167 | 'currency' => null, |
||
168 | 'closePayment' => null, |
||
169 | 'returnUrl' => null, |
||
170 | 'returnMethod' => null, |
||
171 | 'cart' => [ |
||
172 | 'name' => null, |
||
173 | 'quantity' => null, |
||
174 | 'amount' => null, |
||
175 | 'description' => null, |
||
176 | ], |
||
177 | 'description' => null, |
||
178 | 'merchantData' => null, |
||
179 | 'customerId' => null, |
||
180 | 'language' => null, |
||
181 | ]), |
||
182 | new SignatureDataFormatter([ |
||
183 | 'payId' => null, |
||
184 | 'dttm' => null, |
||
185 | 'resultCode' => null, |
||
186 | 'resultMessage' => null, |
||
187 | 'paymentStatus' => null, |
||
188 | 'authCode' => null, |
||
189 | ]) |
||
190 | ); |
||
191 | |||
192 | $data = $response->getData(); |
||
193 | |||
194 | return new PaymentResponse( |
||
195 | $data['payId'], |
||
196 | DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']), |
||
197 | new ResultCode($data['resultCode']), |
||
198 | $data['resultMessage'], |
||
199 | isset($data['paymentStatus']) ? new PaymentStatus($data['paymentStatus']) : null, |
||
200 | $data['authCode'] ?? null |
||
201 | ); |
||
202 | } |
||
203 | |||
205 |