| Conditions | 30 |
| Paths | 80 |
| Total Lines | 142 |
| Code Lines | 86 |
| 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 |
||
| 60 | public function execute($request): void |
||
| 61 | { |
||
| 62 | RequestNotSupportedException::assertSupports($this, $request); |
||
| 63 | |||
| 64 | /** @var PaymentInterface $payment */ |
||
| 65 | $payment = $request->getModel(); |
||
| 66 | |||
| 67 | $details = $payment->getDetails(); |
||
| 68 | |||
| 69 | if ( |
||
| 70 | !isset($details['payment_mollie_id']) && |
||
| 71 | !isset($details['subscription_mollie_id']) && |
||
| 72 | !isset($details['order_mollie_id']) && |
||
| 73 | !isset($details['statusError']) |
||
| 74 | ) { |
||
| 75 | $request->markNew(); |
||
| 76 | $this->loggerAction->addLog(sprintf('Mark new payment with id %s', $payment->getId())); |
||
| 77 | |||
| 78 | return; |
||
| 79 | } |
||
| 80 | |||
| 81 | if (isset($details['statusError'])) { |
||
| 82 | $request->markFailed(); |
||
| 83 | |||
| 84 | return; |
||
| 85 | } |
||
| 86 | |||
| 87 | if (true === isset($details['subscription_mollie_id'])) { |
||
| 88 | try { |
||
| 89 | /** @var Customer $customer */ |
||
| 90 | $customer = $this->mollieApiClient->customers->get($details['customer_mollie_id']); |
||
| 91 | } catch (\Exception $e) { |
||
| 92 | $this->loggerAction->addNegativeLog(sprintf('Error with get customer from mollie with: %s', $e->getMessage())); |
||
| 93 | |||
| 94 | throw new ApiException(sprintf('Error with get customer from mollie with: %s', $e->getMessage())); |
||
| 95 | } |
||
| 96 | |||
| 97 | /** @var Subscription $subscription */ |
||
| 98 | $subscription = $customer->getSubscription($details['subscription_mollie_id']); |
||
| 99 | |||
| 100 | switch ($subscription->status) { |
||
| 101 | case SubscriptionStatus::STATUS_CANCELED: |
||
| 102 | $request->markCanceled(); |
||
| 103 | |||
| 104 | break; |
||
| 105 | case SubscriptionStatus::STATUS_ACTIVE: |
||
| 106 | case SubscriptionStatus::STATUS_PENDING: |
||
| 107 | case SubscriptionStatus::STATUS_COMPLETED: |
||
| 108 | case SubscriptionStatus::STATUS_SUSPENDED: |
||
| 109 | $request->markCaptured(); |
||
| 110 | |||
| 111 | break; |
||
| 112 | default: |
||
| 113 | $request->markUnknown(); |
||
| 114 | |||
| 115 | break; |
||
| 116 | } |
||
| 117 | |||
| 118 | $this->loggerAction->addLog(sprintf('Mark subscription status to: %s', $subscription->status)); |
||
| 119 | |||
| 120 | return; |
||
| 121 | } |
||
| 122 | |||
| 123 | if (false === isset($details['subscription_mollie_id']) && isset($details['payment_mollie_id'])) { |
||
| 124 | try { |
||
| 125 | $molliePayment = $this->mollieApiClient->payments->get($details['payment_mollie_id']); |
||
| 126 | } catch (\Exception $e) { |
||
| 127 | $this->loggerAction->addNegativeLog(sprintf('Error with get payment in status action with id %s', $details['payment_mollie_id'])); |
||
| 128 | |||
| 129 | throw new ApiException(sprintf('Error with get payment in status action with id %s', $details['payment_mollie_id'])); |
||
| 130 | } |
||
| 131 | } |
||
| 132 | |||
| 133 | if (false === isset($details['subscription_mollie_id']) && isset($details['order_mollie_id'])) { |
||
| 134 | try { |
||
| 135 | $order = $this->mollieApiClient->orders->get($details['order_mollie_id'], ['embed' => 'payments']); |
||
| 136 | $payments = $order->_embedded->payments; |
||
| 137 | |||
| 138 | /** @var Payment $payment */ |
||
| 139 | $payment = current($payments); |
||
| 140 | |||
| 141 | if ($payment->method === MealVoucher::MEAL_VOUCHERS) { |
||
| 142 | $this->orderVoucherAdjustmentUpdater->update($payment, $order->metadata->order_id); |
||
| 143 | } |
||
| 144 | |||
| 145 | /** @var Payment $molliePayment */ |
||
| 146 | $molliePayment = $this->mollieApiClient->payments->get($payment->id); |
||
| 147 | $molliePayment->metadata = $order->metadata; |
||
| 148 | } catch (\Exception $e) { |
||
| 149 | $this->loggerAction->addNegativeLog(sprintf('Error with get payment page with id %s', $details['payment_mollie_id'])); |
||
| 150 | |||
| 151 | throw new ApiException(sprintf('Error with get payment page with id %s', $details['payment_mollie_id'])); |
||
| 152 | } |
||
| 153 | } |
||
| 154 | if ($molliePayment->hasRefunds() || $molliePayment->hasChargebacks()) { |
||
|
|
|||
| 155 | if (isset($details['order_mollie_id'])) { |
||
| 156 | $this->orderRefund->refund($order); |
||
| 157 | $this->loggerAction->addLog(sprintf('Mark payment order refunded to: %s', $molliePayment->status)); |
||
| 158 | |||
| 159 | return; |
||
| 160 | } |
||
| 161 | |||
| 162 | $this->paymentRefund->refund($molliePayment); |
||
| 163 | |||
| 164 | $this->loggerAction->addLog(sprintf('Mark payment refunded to: %s', $molliePayment->status)); |
||
| 165 | |||
| 166 | return; |
||
| 167 | } |
||
| 168 | |||
| 169 | switch ($molliePayment->status) { |
||
| 170 | case PaymentStatus::STATUS_PENDING: |
||
| 171 | case PaymentStatus::STATUS_OPEN: |
||
| 172 | $request->markPending(); |
||
| 173 | |||
| 174 | break; |
||
| 175 | case PaymentStatus::STATUS_AUTHORIZED: |
||
| 176 | $request->markAuthorized(); |
||
| 177 | |||
| 178 | break; |
||
| 179 | case PaymentStatus::STATUS_PAID: |
||
| 180 | $request->markCaptured(); |
||
| 181 | |||
| 182 | break; |
||
| 183 | case PaymentStatus::STATUS_CANCELED: |
||
| 184 | $request->markCanceled(); |
||
| 185 | |||
| 186 | break; |
||
| 187 | case PaymentStatus::STATUS_FAILED: |
||
| 188 | $request->markFailed(); |
||
| 189 | |||
| 190 | break; |
||
| 191 | case PaymentStatus::STATUS_EXPIRED: |
||
| 192 | $request->markExpired(); |
||
| 193 | |||
| 194 | break; |
||
| 195 | default: |
||
| 196 | $request->markUnknown(); |
||
| 197 | |||
| 198 | break; |
||
| 199 | } |
||
| 200 | |||
| 201 | $this->loggerAction->addLog(sprintf('Mark payment status to: %s', $molliePayment->status)); |
||
| 202 | } |
||
| 211 |