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