| Conditions | 10 |
| Paths | 80 |
| Total Lines | 79 |
| Code Lines | 48 |
| 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 |
||
| 70 | public function execute($request): void |
||
| 71 | { |
||
| 72 | RequestNotSupportedException::assertSupports($this, $request); |
||
| 73 | |||
| 74 | /** @var PaymentInterface $payment */ |
||
| 75 | $payment = $request->getSource(); |
||
| 76 | |||
| 77 | /** @var OrderInterface $order */ |
||
| 78 | $order = $payment->getOrder(); |
||
| 79 | |||
| 80 | /** @var CustomerInterface $customer */ |
||
| 81 | $customer = $order->getCustomer(); |
||
| 82 | |||
| 83 | $this->gateway->execute($currency = new GetCurrency($payment->getCurrencyCode())); |
||
| 84 | |||
| 85 | $divisor = 10 ** $currency->exp; |
||
| 86 | |||
| 87 | $amount = number_format(abs($payment->getAmount() / $divisor), 2, '.', ''); |
||
| 88 | |||
| 89 | $paymentOptions = $payment->getDetails(); |
||
| 90 | |||
| 91 | if (isset($paymentOptions['metadata'])) { |
||
| 92 | $paymentMethod = $paymentOptions['metadata']['molliePaymentMethods']; |
||
| 93 | $cartToken = $paymentOptions['metadata']['cartToken']; |
||
| 94 | $selectedIssuer = $paymentMethod === PaymentMethod::IDEAL ? $paymentOptions['metadata']['selected_issuer'] : null; |
||
| 95 | } else { |
||
| 96 | $paymentMethod = $paymentOptions['molliePaymentMethods']; |
||
| 97 | $cartToken = $paymentOptions['cartToken']; |
||
| 98 | $selectedIssuer = $paymentMethod === PaymentMethod::IDEAL ? $paymentOptions['issuers']['id'] : null; |
||
| 99 | } |
||
| 100 | |||
| 101 | /** @var MollieGatewayConfigInterface $method */ |
||
| 102 | $method = $this->mollieMethodsRepository->findOneBy(['methodId' => $paymentMethod]); |
||
| 103 | $gatewayConfig = $method->getGateway()->getConfig(); |
||
| 104 | |||
| 105 | $details = [ |
||
| 106 | 'amount' => [ |
||
| 107 | 'value' => "$amount", |
||
| 108 | 'currency' => $currency->code, |
||
| 109 | ], |
||
| 110 | 'description' => $this->paymentDescription->getPaymentDescription($payment, $method, $order), |
||
| 111 | 'metadata' => [ |
||
| 112 | 'order_id' => $order->getId(), |
||
| 113 | 'customer_id' => $customer->getId() ?? null, |
||
| 114 | 'molliePaymentMethods' => $paymentMethod ?? null, |
||
| 115 | 'cartToken' => $cartToken ?? null, |
||
| 116 | 'selected_issuer' => $selectedIssuer ?? null, |
||
| 117 | ], |
||
| 118 | 'full_name' => $customer->getFullName() ?? null, |
||
| 119 | 'email' => $customer->getEmail() ?? null, |
||
| 120 | ]; |
||
| 121 | |||
| 122 | if (null !== $this->customerContext->getCustomer() && true === $gatewayConfig['single_click_enabled']) { |
||
| 123 | $this->gateway->execute($mollieCustomer = new CreateCustomer($details)); |
||
| 124 | $model = $mollieCustomer->getModel(); |
||
| 125 | $details['metadata']['customer_mollie_id'] = $model['customer_mollie_id']; |
||
| 126 | } |
||
| 127 | |||
| 128 | if (true === $this->mollieApiClient->isRecurringSubscription()) { |
||
| 129 | $config = $this->mollieApiClient->getConfig(); |
||
| 130 | |||
| 131 | $details['times'] = $config['times']; |
||
| 132 | $details['interval'] = $config['interval']; |
||
| 133 | } |
||
| 134 | |||
| 135 | if (false === $this->mollieApiClient->isRecurringSubscription()) { |
||
| 136 | $details['customerId'] = $model['customer_mollie_id'] ?? null; |
||
| 137 | $details['metadata']['methodType'] = Options::PAYMENT_API; |
||
| 138 | $details['locale'] = true === in_array($order->getLocaleCode(), MollieGatewayFactoryInterface::LOCALES_AVAILABLE) ? $order->getLocaleCode() : 'en_US'; |
||
| 139 | |||
| 140 | if (array_search($method->getPaymentType(), Options::getAvailablePaymentType()) === Options::ORDER_API) { |
||
| 141 | unset($details['customerId']); |
||
| 142 | |||
| 143 | $details['metadata']['methodType'] = Options::ORDER_API; |
||
| 144 | $details = $this->orderConverter->convert($order, $details, $divisor, $method); |
||
| 145 | } |
||
| 146 | } |
||
| 147 | |||
| 148 | $request->setResult($details); |
||
| 149 | } |
||
| 160 |