Conditions | 5 |
Paths | 6 |
Total Lines | 59 |
Code Lines | 45 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
167 | protected function handleCallback(Request $request) |
||
168 | { |
||
169 | $payment = $this->getPaymentFromRequest($request); |
||
170 | $callbackHandler = $this->get('loevgaard_dandomain_altapay.altapay_callback_handler'); |
||
171 | |||
172 | $psrRequest = $this->createPsrRequest($request); |
||
173 | $callback = $callbackHandler->handleCallback($psrRequest); |
||
174 | |||
175 | if ($callback instanceof XmlCallback) { |
||
176 | $transactions = $callback->getTransactions(); |
||
177 | if (isset($transactions[0])) { |
||
178 | /** @var Transaction $transaction */ |
||
179 | $transaction = $transactions[0]; |
||
180 | |||
181 | $paymentRepository = $this->getPaymentRepository(); |
||
182 | |||
183 | $payment |
||
184 | ->setAltapayId($transaction->getPaymentId()) |
||
185 | ->setCardStatus($transaction->getCardStatus()) |
||
186 | ->setCreditCardToken($transaction->getCreditCardToken()) |
||
187 | ->setCreditCardMaskedPan($transaction->getCreditCardMaskedPan()) |
||
188 | ->setThreeDSecureResult($transaction->getThreeDSecureResult()) |
||
189 | ->setLiableForChargeback($transaction->getLiableForChargeback()) |
||
190 | ->setBlacklistToken($transaction->getBlacklistToken()) |
||
191 | ->setShop($transaction->getShop()) |
||
192 | ->setTerminal($transaction->getTerminal()) |
||
193 | ->setTransactionStatus($transaction->getTransactionStatus()) |
||
194 | ->setReasonCode($transaction->getReasonCode()) |
||
195 | ->setMerchantCurrency($transaction->getMerchantCurrency()) |
||
196 | ->setMerchantCurrencyAlpha($transaction->getMerchantCurrencyAlpha()) |
||
197 | ->setCardHolderCurrency($transaction->getCardHolderCurrency()) |
||
198 | ->setCardHolderCurrencyAlpha($transaction->getCardHolderCurrencyAlpha()) |
||
199 | ->setReservedAmount($transaction->getReservedAmount()) |
||
200 | ->setCapturedAmount($transaction->getCapturedAmount()) |
||
201 | ->setRefundedAmount($transaction->getRefundedAmount()) |
||
202 | ->setRecurringDefaultAmount($transaction->getRecurringDefaultAmount()) |
||
203 | ->setCreatedDate($transaction->getCreatedDate()) |
||
204 | ->setUpdatedDate($transaction->getUpdatedDate()) |
||
205 | ->setPaymentNature($transaction->getPaymentNature()) |
||
206 | ->setSupportsRefunds($transaction->getPaymentNatureService()->isSupportsRefunds()) |
||
207 | ->setSupportsRelease($transaction->getPaymentNatureService()->isSupportsRelease()) |
||
208 | ->setSupportsMultipleCaptures($transaction->getPaymentNatureService()->isSupportsMultipleCaptures()) |
||
209 | ->setSupportsMultipleRefunds($transaction->getPaymentNatureService()->isSupportsMultipleRefunds()) |
||
210 | ->setFraudRiskScore($transaction->getFraudRiskScore()) |
||
211 | ->setFraudExplanation($transaction->getFraudExplanation()) |
||
212 | ; |
||
213 | |||
214 | $paymentRepository->persist($payment); |
||
215 | $paymentRepository->flush(); |
||
216 | } |
||
217 | } |
||
218 | |||
219 | $allowedIps = $this->container->getParameter('loevgaard_dandomain_altapay.altapay_ips'); |
||
220 | if ('prod' === $this->container->get('kernel')->getEnvironment() && !in_array($request->getClientIp(), $allowedIps)) { |
||
221 | throw NotAllowedIpException::create('IP `'.$request->getClientIp().'` is not an allowed IP.', $request, $payment); |
||
222 | } |
||
223 | |||
224 | return $payment; |
||
225 | } |
||
226 | |||
257 |