| Conditions | 11 |
| Paths | 112 |
| Total Lines | 86 |
| Code Lines | 51 |
| 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 |
||
| 25 | public function index() |
||
| 26 | { |
||
| 27 | // Validate cart has products and has stock. |
||
| 28 | if ((!$this->cart->hasProducts()) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) { |
||
| 29 | $this->response->redirect($this->url->link('checkout/cart')); |
||
| 30 | } |
||
| 31 | |||
| 32 | // Validate minimum quantity requirements. |
||
| 33 | $products = $this->cart->getProducts(); |
||
| 34 | |||
| 35 | foreach ($products as $product) { |
||
| 36 | $product_total = 0; |
||
| 37 | |||
| 38 | foreach ($products as $product_2) { |
||
| 39 | if ($product_2['product_id'] == $product['product_id']) { |
||
| 40 | $product_total += $product_2['quantity']; |
||
| 41 | } |
||
| 42 | } |
||
| 43 | |||
| 44 | if ($product['minimum'] > $product_total) { |
||
| 45 | $this->response->redirect($this->url->link('checkout/cart')); |
||
| 46 | } |
||
| 47 | } |
||
| 48 | |||
| 49 | $this->load->language('checkout/checkout'); |
||
| 50 | |||
| 51 | $this->document->setTitle($this->language->get('heading_title')); |
||
| 52 | |||
| 53 | $data['breadcrumbs'] = array(); |
||
| 54 | |||
| 55 | $data['breadcrumbs'][] = array( |
||
| 56 | 'text' => $this->language->get('text_home'), |
||
| 57 | 'href' => $this->url->link('common/home') |
||
| 58 | ); |
||
| 59 | |||
| 60 | $data['breadcrumbs'][] = array( |
||
| 61 | 'text' => $this->language->get('text_cart'), |
||
| 62 | 'href' => $this->url->link('checkout/cart') |
||
| 63 | ); |
||
| 64 | |||
| 65 | $data['breadcrumbs'][] = array( |
||
| 66 | 'text' => $this->language->get('heading_title'), |
||
| 67 | 'href' => $this->url->link('checkout/checkout', '', true) |
||
| 68 | ); |
||
| 69 | |||
| 70 | $data['heading_title'] = $this->language->get('heading_title'); |
||
| 71 | |||
| 72 | $data['text_checkout_option'] = sprintf($this->language->get('text_checkout_option'), 1); |
||
| 73 | $data['text_checkout_account'] = sprintf($this->language->get('text_checkout_account'), 2); |
||
| 74 | $data['text_checkout_payment_address'] = sprintf($this->language->get('text_checkout_payment_address'), 2); |
||
| 75 | $data['text_checkout_shipping_address'] = sprintf($this->language->get('text_checkout_shipping_address'), 3); |
||
| 76 | $data['text_checkout_shipping_method'] = sprintf($this->language->get('text_checkout_shipping_method'), 4); |
||
| 77 | |||
| 78 | if ($this->cart->hasShipping()) { |
||
| 79 | $data['text_checkout_payment_method'] = sprintf($this->language->get('text_checkout_payment_method'), 5); |
||
| 80 | $data['text_checkout_confirm'] = sprintf($this->language->get('text_checkout_confirm'), 6); |
||
| 81 | } else { |
||
| 82 | $data['text_checkout_payment_method'] = sprintf($this->language->get('text_checkout_payment_method'), 3); |
||
| 83 | $data['text_checkout_confirm'] = sprintf($this->language->get('text_checkout_confirm'), 4); |
||
| 84 | } |
||
| 85 | |||
| 86 | if (isset($this->session->data['error'])) { |
||
| 87 | $data['error_warning'] = $this->session->data['error']; |
||
| 88 | unset($this->session->data['error']); |
||
| 89 | } else { |
||
| 90 | $data['error_warning'] = ''; |
||
| 91 | } |
||
| 92 | |||
| 93 | $data['logged'] = $this->customer->isLogged(); |
||
| 94 | |||
| 95 | if (isset($this->session->data['account'])) { |
||
| 96 | $data['account'] = $this->session->data['account']; |
||
| 97 | } else { |
||
| 98 | $data['account'] = ''; |
||
| 99 | } |
||
| 100 | |||
| 101 | $data['shipping_required'] = $this->cart->hasShipping(); |
||
| 102 | |||
| 103 | $data['column'] = $this->load->controller('common/column'); |
||
| 104 | |||
| 105 | $data['content_top'] = $this->load->controller('common/content_top'); |
||
| 106 | $data['content_bottom'] = $this->load->controller('common/content_bottom'); |
||
| 107 | $data['footer'] = $this->load->controller('common/footer'); |
||
| 108 | $data['header'] = $this->load->controller('common/header'); |
||
| 109 | |||
| 110 | $this->response->setOutput($this->load->view('checkout/checkout', $data)); |
||
| 111 | } |
||
| 166 |