| Conditions | 6 |
| Paths | 32 |
| Total Lines | 55 |
| Code Lines | 40 |
| 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 |
||
| 52 | public function resolve(OrderInterface $order, MollieGatewayConfigInterface $mollieGatewayConfig, array $details): void |
||
| 53 | { |
||
| 54 | $this->apiClientKeyResolver->getClientWithKey(); |
||
| 55 | $details = $this->convertOrder->convert($order, $details, 100, $mollieGatewayConfig); |
||
| 56 | $customer = $order->getCustomer(); |
||
| 57 | |||
| 58 | $orderExpiredTime = $mollieGatewayConfig->getOrderExpiration(); |
||
| 59 | if (null !== $orderExpiredTime) { |
||
| 60 | $interval = new \DateInterval('P' . $orderExpiredTime . 'D'); |
||
| 61 | $dateExpired = new \DateTimeImmutable('now'); |
||
| 62 | $dateExpired = $dateExpired->add($interval); |
||
| 63 | } |
||
| 64 | |||
| 65 | /** @var PaymentInterface $payment */ |
||
| 66 | $payment = $order->getLastPayment(); |
||
| 67 | $refundToken = $payment->getDetails()['refund_token']; |
||
| 68 | |||
| 69 | $metadata = [ |
||
| 70 | 'order_id' => $order->getId(), |
||
| 71 | 'customer_id' => null !== $customer ? $customer->getId() : null, |
||
| 72 | 'molliePaymentMethods' => PaymentMethod::APPLEPAY, |
||
| 73 | 'refund_token' => $refundToken, |
||
| 74 | 'methodType' => Options::ORDER_API, |
||
| 75 | ]; |
||
| 76 | |||
| 77 | try { |
||
| 78 | $response = $this->mollieApiClient->orders->create( |
||
| 79 | [ |
||
| 80 | 'method' => PaymentMethod::APPLEPAY, |
||
| 81 | 'payment' => [ |
||
| 82 | 'applePayPaymentToken' => $details['applePayDirectToken'], |
||
| 83 | ], |
||
| 84 | 'amount' => $details['amount'], |
||
| 85 | 'billingAddress' => $details['billingAddress'], |
||
| 86 | 'shippingAddress' => $details['shippingAddress'], |
||
| 87 | 'locale' => $order->getLocaleCode(), |
||
| 88 | 'orderNumber' => $details['orderNumber'], |
||
| 89 | 'redirectUrl' => $details['backurl'], |
||
| 90 | 'lines' => $details['lines'], |
||
| 91 | 'metadata' => $metadata, |
||
| 92 | 'expiresAt' => isset($dateExpired) ? |
||
| 93 | $dateExpired->format('Y-m-d') : |
||
| 94 | (new \DateTimeImmutable('now'))->format('Y-m-d'), |
||
| 95 | ] |
||
| 96 | ); |
||
| 97 | if ($response->status === OrderStatus::STATUS_PAID) { |
||
| 98 | $this->paymentApplePayDirectProvider->applyRequiredTransition($payment, PaymentInterface::STATE_COMPLETED); |
||
| 99 | |||
| 100 | $paymentDetails = $payment->getDetails(); |
||
| 101 | $paymentDetails['order_mollie_id'] = $response->id; |
||
| 102 | $paymentDetails['metadata'] = $metadata; |
||
| 103 | $payment->setDetails($paymentDetails); |
||
| 104 | } |
||
| 105 | } catch (ApiException $e) { |
||
| 106 | throw new ApiException($e->getMessage()); |
||
| 107 | } |
||
| 110 |