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