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