Conditions | 10 |
Paths | 13 |
Total Lines | 67 |
Code Lines | 36 |
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 |
||
71 | public function __invoke(Request $request): Response |
||
72 | { |
||
73 | /** @var PaymentInterface|null $payment */ |
||
74 | $payment = $this->paymentRepository->find($request->get('id')); |
||
75 | |||
76 | if (null === $payment) { |
||
77 | $this->loggerAction->addNegativeLog(sprintf('Not fount payment in refund')); |
||
78 | |||
79 | throw new NotFoundHttpException(); |
||
80 | } |
||
81 | |||
82 | /** @var PaymentMethodInterface $paymentMethod */ |
||
83 | $paymentMethod = $payment->getMethod(); |
||
84 | |||
85 | /** @var GatewayConfigInterface $gatewayConfig */ |
||
86 | $gatewayConfig = $paymentMethod->getGatewayConfig(); |
||
87 | $factoryName = $gatewayConfig->getFactoryName() ?? null; |
||
|
|||
88 | |||
89 | if (MollieGatewayFactory::FACTORY_NAME !== $factoryName) { |
||
90 | $this->applyStateMachineTransition($payment); |
||
91 | |||
92 | $this->session->getFlashBag()->add('success', 'sylius.payment.refunded'); |
||
93 | $this->loggerAction->addLog(sprintf('Refunded successfully')); |
||
94 | |||
95 | return $this->redirectToReferer($request); |
||
96 | } |
||
97 | if ( |
||
98 | (!isset($payment->getDetails()['payment_mollie_id']) || !isset($payment->getDetails()['metadata']['refund_token'])) && |
||
99 | !isset($payment->getDetails()['order_mollie_id']) |
||
100 | ) { |
||
101 | $this->applyStateMachineTransition($payment); |
||
102 | |||
103 | $this->session->getFlashBag()->add('info', 'bitbag_sylius_mollie_plugin.ui.refunded_only_locally'); |
||
104 | $this->loggerAction->addLog(sprintf('Refunded only locally')); |
||
105 | |||
106 | return $this->redirectToReferer($request); |
||
107 | } |
||
108 | |||
109 | $hash = $payment->getDetails()['metadata']['refund_token']; |
||
110 | |||
111 | /** @var TokenInterface|null $token */ |
||
112 | $token = $this->payum->getTokenStorage()->find($hash); |
||
113 | |||
114 | if (null === $token || !$token instanceof TokenInterface) { |
||
115 | $this->loggerAction->addNegativeLog(sprintf('A token with hash `%s` could not be found.', $hash)); |
||
116 | |||
117 | throw new BadRequestHttpException(sprintf('A token with hash `%s` could not be found.', $hash)); |
||
118 | } |
||
119 | |||
120 | $gateway = $this->payum->getGateway($token->getGatewayName()); |
||
121 | |||
122 | try { |
||
123 | if (isset($payment->getDetails()['order_mollie_id'])) { |
||
124 | $gateway->execute(new RefundOrder($token)); |
||
125 | } else { |
||
126 | $gateway->execute(new RefundAction($token)); |
||
127 | } |
||
128 | |||
129 | $this->applyStateMachineTransition($payment); |
||
130 | |||
131 | $this->session->getFlashBag()->add('success', 'sylius.payment.refunded'); |
||
132 | } catch (UpdateHandlingException $e) { |
||
133 | $this->loggerAction->addNegativeLog(sprintf('Error with refund: %s', $e->getMessage())); |
||
134 | $this->session->getFlashBag()->add('error', $e->getMessage()); |
||
135 | } |
||
136 | |||
137 | return $this->redirectToReferer($request); |
||
138 | } |
||
161 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.