| Conditions | 16 |
| Paths | 116 |
| Total Lines | 132 |
| Code Lines | 77 |
| 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 | $this->load->language('common/cart'); |
||
| 28 | |||
| 29 | // Totals |
||
| 30 | $this->load->model('extension/extension'); |
||
| 31 | |||
| 32 | $totals = array(); |
||
| 33 | $total = 0; |
||
| 34 | |||
| 35 | // Because __call can not keep var references so we put them into an array. |
||
| 36 | $total_data = array( |
||
| 37 | 'totals' => &$totals, |
||
| 38 | 'total' => &$total |
||
| 39 | ); |
||
| 40 | |||
| 41 | // Display prices |
||
| 42 | if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) { |
||
| 43 | $sort_order = array(); |
||
| 44 | |||
| 45 | $results = $this->model_extension_extension->getExtensions('total'); |
||
| 46 | |||
| 47 | foreach ($results as $key => $value) { |
||
| 48 | $sort_order[$key] = $this->config->get($value['code'] . '_sort_order'); |
||
| 49 | } |
||
| 50 | |||
| 51 | array_multisort($sort_order, SORT_ASC, $results); |
||
| 52 | |||
| 53 | foreach ($results as $result) { |
||
| 54 | if ($this->config->get($result['code'] . '_status')) { |
||
| 55 | $this->load->model('extension/total/' . $result['code']); |
||
| 56 | |||
| 57 | // We have to put the totals in an array so that they pass by reference. |
||
| 58 | $this->{'model_extension_total_' . $result['code']}->getTotal($total_data); |
||
| 59 | } |
||
| 60 | } |
||
| 61 | |||
| 62 | $sort_order = array(); |
||
| 63 | |||
| 64 | foreach ($totals as $key => $value) { |
||
| 65 | $sort_order[$key] = $value['sort_order']; |
||
| 66 | } |
||
| 67 | |||
| 68 | array_multisort($sort_order, SORT_ASC, $totals); |
||
| 69 | } |
||
| 70 | |||
| 71 | $data['text_empty'] = $this->language->get('text_empty'); |
||
| 72 | $data['text_empty_info'] = $this->language->get('text_empty_info'); |
||
| 73 | $data['text_cart'] = $this->language->get('text_cart'); |
||
| 74 | $data['text_checkout'] = $this->language->get('text_checkout'); |
||
| 75 | |||
| 76 | $data['text_items'] = $this->language->get('text_items'); |
||
| 77 | $data['products_count'] = $this->cart->countProducts(); |
||
| 78 | $data['products_price'] = $this->currency->format($total, $this->session->data['currency']); |
||
| 79 | |||
| 80 | $data['text_header_cart'] = $this->language->get('text_header_cart'); |
||
| 81 | $data['text_header_cart_qt_info'] = $this->language->get('text_header_cart_qt_info'); |
||
| 82 | |||
| 83 | $data['button_remove'] = $this->language->get('button_remove'); |
||
| 84 | |||
| 85 | |||
| 86 | $this->load->model('tool/upload'); |
||
| 87 | |||
| 88 | $data['products'] = array(); |
||
| 89 | |||
| 90 | foreach ($this->cart->getProducts() as $product) { |
||
| 91 | if ($product['image']) { |
||
| 92 | $image = '/public_html/assets/images/' . $product['image']; |
||
| 93 | } else { |
||
| 94 | $image = '/public_html/assets/images/no_image.png'; |
||
| 95 | } |
||
| 96 | |||
| 97 | $option_data = array(); |
||
| 98 | |||
| 99 | foreach ($product['option'] as $option) { |
||
| 100 | if ($option['type'] != 'file') { |
||
| 101 | $value = $option['value']; |
||
| 102 | } else { |
||
| 103 | $upload_info = $this->model_tool_upload->getUploadByCode($option['value']); |
||
| 104 | |||
| 105 | if ($upload_info) { |
||
| 106 | $value = $upload_info['name']; |
||
| 107 | } else { |
||
| 108 | $value = ''; |
||
| 109 | } |
||
| 110 | } |
||
| 111 | |||
| 112 | $option_data[] = array( |
||
| 113 | 'name' => $option['name'], |
||
| 114 | 'value' => (\voku\helper\UTF8::strlen($value) > 20 ? \voku\helper\UTF8::substr($value, 0, 20) . '..' : $value), |
||
| 115 | 'type' => $option['type'] |
||
| 116 | ); |
||
| 117 | } |
||
| 118 | |||
| 119 | // Display prices |
||
| 120 | if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) { |
||
| 121 | $unit_price = $product['price']; |
||
| 122 | |||
| 123 | $price = $this->currency->format($unit_price, $this->session->data['currency']); |
||
| 124 | $total = $this->currency->format($unit_price * $product['quantity'], $this->session->data['currency']); |
||
| 125 | } else { |
||
| 126 | $price = false; |
||
| 127 | $total = false; |
||
| 128 | } |
||
| 129 | |||
| 130 | $data['products'][] = array( |
||
| 131 | 'cart_id' => $product['cart_id'], |
||
| 132 | 'thumb' => $image, |
||
| 133 | 'name' => $product['name'], |
||
| 134 | 'model' => $product['model'], |
||
| 135 | 'option' => $option_data, |
||
| 136 | 'quantity' => $product['quantity'], |
||
| 137 | 'price' => $price, |
||
| 138 | 'total' => $total, |
||
| 139 | 'href' => $this->url->link('product/product', 'product_id=' . $product['product_id']) |
||
| 140 | ); |
||
| 141 | } |
||
| 142 | |||
| 143 | $data['totals'] = array(); |
||
| 144 | |||
| 145 | foreach ($totals as $total) { |
||
| 146 | $data['totals'][] = array( |
||
| 147 | 'title' => $total['title'], |
||
| 148 | 'text' => $this->currency->format($total['value'], $this->session->data['currency']), |
||
| 149 | ); |
||
| 150 | } |
||
| 151 | |||
| 152 | $data['cart'] = $this->url->link('checkout/cart'); |
||
| 153 | // $data['checkout'] = $this->url->link('checkout/checkout', '', true); |
||
| 154 | $data['checkout'] = $this->url->link('checkout/onepagecheckout', '', true); |
||
| 155 | |||
| 156 | return $this->load->view('common/cart', $data); |
||
| 157 | } |
||
| 164 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.