Conditions | 7 |
Paths | 6 |
Total Lines | 101 |
Code Lines | 68 |
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 |
||
79 | public function newAction($terminal, Request $request) |
||
80 | { |
||
81 | $terminalManager = $this->container->get('loevgaard_pakkelabels.terminal_manager'); |
||
82 | $paymentManager = $this->container->get('loevgaard_pakkelabels.payment_manager'); |
||
83 | |||
84 | // convert symfony request to PSR7 request |
||
85 | $psr7Factory = new DiactorosFactory(); |
||
86 | $psrRequest = $psr7Factory->createRequest($request); |
||
87 | |||
88 | $handler = new Handler( |
||
89 | $psrRequest, |
||
90 | $this->container->getParameter('loevgaard_pakkelabels.shared_key_1'), |
||
91 | $this->container->getParameter('loevgaard_pakkelabels.shared_key_2') |
||
92 | ); |
||
93 | |||
94 | $dandomainPaymentRequest = $handler->getPaymentRequest(); |
||
95 | |||
96 | $paymentEntity = $paymentManager->createPaymentFromDandomainPaymentRequest($dandomainPaymentRequest); |
||
97 | $paymentManager->update($paymentEntity); |
||
98 | |||
99 | $terminalEntity = $terminalManager->findTerminalBySlug($terminal, true); |
||
100 | if (!$terminalEntity) { |
||
101 | // @todo fix translation |
||
102 | throw TerminalNotFoundException::create('Terminal `'.$terminal.'` does not exist', $request, $paymentEntity); |
||
103 | } |
||
104 | |||
105 | if (!$handler->checksumMatches()) { |
||
106 | // @todo fix translation |
||
107 | throw ChecksumMismatchException::create('Checksum mismatch. Try again', $request, $paymentEntity); |
||
108 | } |
||
109 | |||
110 | $paymentRequestPayload = new PaymentRequestPayload( |
||
111 | $terminalEntity->getTitle(), |
||
112 | $dandomainPaymentRequest->getOrderId(), |
||
113 | $dandomainPaymentRequest->getTotalAmount(), |
||
114 | $dandomainPaymentRequest->getCurrencySymbol() |
||
115 | ); |
||
116 | |||
117 | foreach ($dandomainPaymentRequest->getPaymentLines() as $paymentLine) { |
||
118 | $orderLinePayload = new OrderLinePayload( |
||
119 | $paymentLine->getName(), |
||
120 | $paymentLine->getProductNumber(), |
||
121 | $paymentLine->getQuantity(), |
||
122 | $paymentLine->getPrice() |
||
123 | ); |
||
124 | $orderLinePayload->setTaxPercent($paymentLine->getVat()); |
||
125 | |||
126 | $paymentRequestPayload->addOrderLine($orderLinePayload); |
||
127 | } |
||
128 | |||
129 | $customerInfoPayload = new CustomerInfoPayload(); |
||
130 | $customerNames = explode(' ', $dandomainPaymentRequest->getCustomerName(), 2); |
||
131 | $shippingNames = explode(' ', $dandomainPaymentRequest->getDeliveryName(), 2); |
||
132 | $customerInfoPayload |
||
133 | ->setBillingFirstName($customerNames[0] ?? '') |
||
134 | ->setBillingLastName($customerNames[1] ?? '') |
||
135 | ->setBillingAddress( |
||
136 | $dandomainPaymentRequest->getCustomerAddress(). |
||
137 | ($dandomainPaymentRequest->getCustomerAddress2() ? "\r\n".$dandomainPaymentRequest->getCustomerAddress2() : '') |
||
138 | ) |
||
139 | ->setBillingPostal($dandomainPaymentRequest->getCustomerZipCode()) |
||
140 | ->setBillingCity($dandomainPaymentRequest->getCustomerCity()) |
||
141 | ->setBillingCountry($dandomainPaymentRequest->getCustomerCountry()) |
||
142 | ->setShippingFirstName($shippingNames[0] ?? '') |
||
143 | ->setShippingLastName($shippingNames[1] ?? '') |
||
144 | ->setShippingAddress( |
||
145 | $dandomainPaymentRequest->getDeliveryAddress(). |
||
146 | ($dandomainPaymentRequest->getDeliveryAddress2() ? "\r\n".$dandomainPaymentRequest->getDeliveryAddress2() : '') |
||
147 | ) |
||
148 | ->setShippingPostal($dandomainPaymentRequest->getDeliveryZipCode()) |
||
149 | ->setShippingCity($dandomainPaymentRequest->getDeliveryCity()) |
||
150 | ->setShippingCountry($dandomainPaymentRequest->getDeliveryCountry()) |
||
151 | ; |
||
152 | $paymentRequestPayload->setCustomerInfo($customerInfoPayload); |
||
153 | |||
154 | $configPayload = new ConfigPayload(); |
||
155 | $configPayload |
||
156 | ->setCallbackForm($this->generateUrl('loevgaard_pakkelabels_callback_form', [], UrlGeneratorInterface::ABSOLUTE_URL)) |
||
157 | ->setCallbackOk($this->generateUrl('loevgaard_pakkelabels_callback_ok', [], UrlGeneratorInterface::ABSOLUTE_URL)) |
||
158 | ->setCallbackFail($this->generateUrl('loevgaard_pakkelabels_callback_fail', [], UrlGeneratorInterface::ABSOLUTE_URL)) |
||
159 | ->setCallbackRedirect($this->generateUrl('loevgaard_pakkelabels_callback_redirect', [], UrlGeneratorInterface::ABSOLUTE_URL)) |
||
160 | ->setCallbackOpen($this->generateUrl('loevgaard_pakkelabels_callback_open', [], UrlGeneratorInterface::ABSOLUTE_URL)) |
||
161 | ->setCallbackNotification($this->generateUrl('loevgaard_pakkelabels_callback_notification', [], UrlGeneratorInterface::ABSOLUTE_URL)) |
||
162 | ; |
||
163 | $paymentRequestPayload->setConfig($configPayload); |
||
164 | |||
165 | $paymentRequestPayload |
||
166 | ->setCookiePart($this->getParameter('loevgaard_pakkelabels.cookie_payment_id'), $paymentEntity->getId()) |
||
167 | ->setCookiePart($this->getParameter('loevgaard_pakkelabels.cookie_checksum_complete'), $handler->getChecksum2()) |
||
168 | ; |
||
169 | |||
170 | $altapay = $this->container->get('loevgaard_pakkelabels.altapay_client'); |
||
171 | $response = $altapay->createPaymentRequest($paymentRequestPayload); |
||
172 | |||
173 | if (!$response->isSuccessful()) { |
||
174 | // @todo fix translation |
||
175 | throw AltapayPaymentRequestException::create('An error occured during payment request. Try again. Message from gateway: '.$response->getErrorMessage(), $request, $paymentEntity); |
||
176 | } |
||
177 | |||
178 | return new RedirectResponse($response->getUrl()); |
||
179 | } |
||
180 | } |
||
181 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.