| Conditions | 14 |
| Paths | 60 |
| Total Lines | 67 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 83 | public function submitpayment($data, $form) |
||
|
|
|||
| 84 | { |
||
| 85 | $data = $form->getData(); |
||
| 86 | |||
| 87 | $cancelUrl = $this->getFailureLink() ? $this->getFailureLink() : $this->controller->Link(); |
||
| 88 | |||
| 89 | $order = $this->config->getOrder(); |
||
| 90 | |||
| 91 | // final recalculation, before making payment |
||
| 92 | $order->calculate(); |
||
| 93 | |||
| 94 | if ($order->isChanged()) { |
||
| 95 | $order->write(); |
||
| 96 | } |
||
| 97 | |||
| 98 | // handle cases where order total is 0. Note that the order will appear |
||
| 99 | // as "paid", but without a Payment record attached. |
||
| 100 | if ($order->GrandTotal() == 0 && Order::config()->allow_zero_order_total) { |
||
| 101 | if (!$this->orderProcessor->placeOrder()) { |
||
| 102 | $form->sessionMessage($this->orderProcessor->getError()); |
||
| 103 | return $this->controller->redirectBack(); |
||
| 104 | } |
||
| 105 | return $this->controller->redirect($this->getSuccessLink()); |
||
| 106 | } |
||
| 107 | |||
| 108 | // try to place order before payment, if configured |
||
| 109 | if (Order::config()->place_before_payment) { |
||
| 110 | if (!$this->orderProcessor->placeOrder()) { |
||
| 111 | $form->sessionMessage($this->orderProcessor->getError()); |
||
| 112 | return $this->controller->redirectBack(); |
||
| 113 | } |
||
| 114 | $cancelUrl = $this->orderProcessor->getReturnUrl(); |
||
| 115 | } |
||
| 116 | |||
| 117 | // if we got here from checkoutSubmit and there's a namespaced Component that provides payment data, |
||
| 118 | // we need to strip the inputs down to only the checkout component. |
||
| 119 | $components = $this->config->getComponents(); |
||
| 120 | if ($components->first() instanceof CheckoutComponentNamespaced) { |
||
| 121 | foreach ($components as $component) { |
||
| 122 | if ($component->Proxy()->providesPaymentData()) { |
||
| 123 | $data = array_merge($data, $component->unnamespaceData($data)); |
||
| 124 | } |
||
| 125 | } |
||
| 126 | } |
||
| 127 | |||
| 128 | $gateway = Checkout::get($order)->getSelectedPaymentMethod(false); |
||
| 129 | $fieldFactory = new GatewayFieldsFactory($gateway); |
||
| 130 | |||
| 131 | // This is where the payment is actually attempted |
||
| 132 | $paymentResponse = $this->orderProcessor->makePayment( |
||
| 133 | $gateway, |
||
| 134 | $fieldFactory->normalizeFormData($data), |
||
| 135 | $this->getSuccessLink(), |
||
| 136 | $cancelUrl |
||
| 137 | ); |
||
| 138 | |||
| 139 | $response = null; |
||
| 140 | if ($this->controller->hasMethod('processPaymentResponse')) { |
||
| 141 | $response = $this->controller->processPaymentResponse($paymentResponse, $form); |
||
| 142 | } elseif ($paymentResponse && !$paymentResponse->isError()) { |
||
| 143 | $response = $paymentResponse->redirectOrRespond(); |
||
| 144 | } else { |
||
| 145 | $form->sessionMessage($this->orderProcessor->getError(), 'bad'); |
||
| 146 | $response = $this->controller->redirectBack(); |
||
| 147 | } |
||
| 148 | |||
| 149 | return $response; |
||
| 150 | } |
||
| 168 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.