| Conditions | 33 |
| Paths | > 20000 |
| Total Lines | 237 |
| Code Lines | 141 |
| 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('checkout/cart'); |
||
| 28 | |||
| 29 | $this->document->setTitle($this->language->get('heading_title')); |
||
| 30 | |||
| 31 | $data['breadcrumbs'] = array(); |
||
| 32 | |||
| 33 | $data['breadcrumbs'][] = array( |
||
| 34 | 'href' => $this->url->link('common/home'), |
||
| 35 | 'text' => $this->language->get('text_home') |
||
| 36 | ); |
||
| 37 | |||
| 38 | $data['breadcrumbs'][] = array( |
||
| 39 | 'href' => $this->url->link('checkout/cart'), |
||
| 40 | 'text' => $this->language->get('heading_title') |
||
| 41 | ); |
||
| 42 | |||
| 43 | if ($this->cart->hasProducts()) { |
||
| 44 | $data['heading_title'] = $this->language->get('heading_title'); |
||
| 45 | |||
| 46 | $data['text_next'] = $this->language->get('text_next'); |
||
| 47 | $data['text_next_choice'] = $this->language->get('text_next_choice'); |
||
| 48 | |||
| 49 | $data['column_image'] = $this->language->get('column_image'); |
||
| 50 | $data['column_name'] = $this->language->get('column_name'); |
||
| 51 | $data['column_model'] = $this->language->get('column_model'); |
||
| 52 | $data['column_quantity'] = $this->language->get('column_quantity'); |
||
| 53 | $data['column_price'] = $this->language->get('column_price'); |
||
| 54 | $data['column_total'] = $this->language->get('column_total'); |
||
| 55 | |||
| 56 | $data['button_update'] = $this->language->get('button_update'); |
||
| 57 | $data['button_remove'] = $this->language->get('button_remove'); |
||
| 58 | $data['button_shopping'] = $this->language->get('button_shopping'); |
||
| 59 | $data['button_checkout'] = $this->language->get('button_checkout'); |
||
| 60 | |||
| 61 | if (!$this->cart->hasStock() && (!$this->config->get('config_stock_checkout') || $this->config->get('config_stock_warning'))) { |
||
| 62 | $data['error_warning'] = $this->language->get('error_stock'); |
||
| 63 | } elseif (isset($this->session->data['error'])) { |
||
| 64 | $data['error_warning'] = $this->session->data['error']; |
||
| 65 | |||
| 66 | unset($this->session->data['error']); |
||
| 67 | } else { |
||
| 68 | $data['error_warning'] = ''; |
||
| 69 | } |
||
| 70 | |||
| 71 | if ($this->config->get('config_customer_price') && !$this->customer->isLogged()) { |
||
| 72 | $data['attention'] = sprintf($this->language->get('text_login'), $this->url->link('account/login'), $this->url->link('account/register')); |
||
| 73 | } else { |
||
| 74 | $data['attention'] = ''; |
||
| 75 | } |
||
| 76 | |||
| 77 | if (isset($this->session->data['success'])) { |
||
| 78 | $data['success'] = $this->session->data['success']; |
||
| 79 | |||
| 80 | unset($this->session->data['success']); |
||
| 81 | } else { |
||
| 82 | $data['success'] = ''; |
||
| 83 | } |
||
| 84 | |||
| 85 | $data['action'] = $this->url->link('checkout/cart/edit', '', true); |
||
| 86 | |||
| 87 | |||
| 88 | $this->load->model('tool/upload'); |
||
| 89 | |||
| 90 | $data['products'] = array(); |
||
| 91 | |||
| 92 | $products = $this->cart->getProducts(); |
||
| 93 | |||
| 94 | foreach ($products as $product) { |
||
| 95 | $product_total = 0; |
||
| 96 | |||
| 97 | foreach ($products as $product_2) { |
||
| 98 | if ($product_2['product_id'] == $product['product_id']) { |
||
| 99 | $product_total += $product_2['quantity']; |
||
| 100 | } |
||
| 101 | } |
||
| 102 | |||
| 103 | if ($product['minimum'] > $product_total) { |
||
| 104 | $data['error_warning'] = sprintf($this->language->get('error_minimum'), $product['name'], $product['minimum']); |
||
| 105 | } |
||
| 106 | |||
| 107 | if ($product['image']) { |
||
| 108 | $image = '/public_html/assets/images/' . $product['image']; |
||
| 109 | } else { |
||
| 110 | $image = '/public_html/assets/images/no_image.png'; |
||
| 111 | } |
||
| 112 | |||
| 113 | $option_data = array(); |
||
| 114 | |||
| 115 | foreach ($product['option'] as $option) { |
||
| 116 | if ($option['type'] != 'file') { |
||
| 117 | $value = $option['value']; |
||
| 118 | } else { |
||
| 119 | $upload_info = $this->model_tool_upload->getUploadByCode($option['value']); |
||
| 120 | |||
| 121 | if ($upload_info) { |
||
| 122 | $value = $upload_info['name']; |
||
| 123 | } else { |
||
| 124 | $value = ''; |
||
| 125 | } |
||
| 126 | } |
||
| 127 | |||
| 128 | $option_data[] = array( |
||
| 129 | 'name' => $option['name'], |
||
| 130 | 'value' => (\voku\helper\UTF8::strlen($value) > 20 ? \voku\helper\UTF8::substr($value, 0, 20) . '..' : $value) |
||
| 131 | ); |
||
| 132 | } |
||
| 133 | |||
| 134 | // Display prices |
||
| 135 | if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) { |
||
| 136 | $unit_price = $product['price']; |
||
| 137 | |||
| 138 | $price = $this->currency->format($unit_price, $this->session->data['currency']); |
||
| 139 | $total = $this->currency->format($unit_price * $product['quantity'], $this->session->data['currency']); |
||
| 140 | } else { |
||
| 141 | $price = false; |
||
| 142 | $total = false; |
||
| 143 | } |
||
| 144 | |||
| 145 | |||
| 146 | $data['products'][] = array( |
||
| 147 | 'cart_id' => $product['cart_id'], |
||
| 148 | 'thumb' => $image, |
||
| 149 | 'name' => $product['name'], |
||
| 150 | 'model' => $product['model'], |
||
| 151 | 'option' => $option_data, |
||
| 152 | 'quantity' => $product['quantity'], |
||
| 153 | 'stock' => $product['stock'] ? true : !(!$this->config->get('config_stock_checkout') || $this->config->get('config_stock_warning')), |
||
| 154 | 'reward' => ($product['reward'] ? sprintf($this->language->get('text_points'), $product['reward']) : ''), |
||
| 155 | 'price' => $price, |
||
| 156 | 'total' => $total, |
||
| 157 | 'href' => $this->url->link('product/product', 'product_id=' . $product['product_id']) |
||
| 158 | ); |
||
| 159 | } |
||
| 160 | |||
| 161 | // Totals |
||
| 162 | $this->load->model('extension/extension'); |
||
| 163 | |||
| 164 | $totals = array(); |
||
| 165 | $total = 0; |
||
| 166 | |||
| 167 | // Because __call can not keep var references so we put them into an array. |
||
| 168 | $total_data = array( |
||
| 169 | 'totals' => &$totals, |
||
| 170 | 'total' => &$total |
||
| 171 | ); |
||
| 172 | |||
| 173 | // Display prices |
||
| 174 | if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) { |
||
| 175 | $sort_order = array(); |
||
| 176 | |||
| 177 | $results = $this->model_extension_extension->getExtensions('total'); |
||
| 178 | |||
| 179 | foreach ($results as $key => $value) { |
||
| 180 | $sort_order[$key] = $this->config->get($value['code'] . '_sort_order'); |
||
| 181 | } |
||
| 182 | |||
| 183 | array_multisort($sort_order, SORT_ASC, $results); |
||
| 184 | |||
| 185 | foreach ($results as $result) { |
||
| 186 | if ($this->config->get($result['code'] . '_status')) { |
||
| 187 | $this->load->model('extension/total/' . $result['code']); |
||
| 188 | |||
| 189 | // We have to put the totals in an array so that they pass by reference. |
||
| 190 | $this->{'model_extension_total_' . $result['code']}->getTotal($total_data); |
||
| 191 | } |
||
| 192 | } |
||
| 193 | |||
| 194 | $sort_order = array(); |
||
| 195 | |||
| 196 | foreach ($totals as $key => $value) { |
||
| 197 | $sort_order[$key] = $value['sort_order']; |
||
| 198 | } |
||
| 199 | |||
| 200 | array_multisort($sort_order, SORT_ASC, $totals); |
||
| 201 | } |
||
| 202 | |||
| 203 | $data['totals'] = array(); |
||
| 204 | |||
| 205 | foreach ($totals as $total) { |
||
| 206 | $data['totals'][] = array( |
||
| 207 | 'title' => $total['title'], |
||
| 208 | 'text' => $this->currency->format($total['value'], $this->session->data['currency']) |
||
| 209 | ); |
||
| 210 | } |
||
| 211 | |||
| 212 | $data['continue'] = $this->url->link('common/home'); |
||
| 213 | |||
| 214 | // $data['checkout'] = $this->url->link('checkout/checkout', '', true); |
||
| 215 | $data['checkout'] = $this->url->link('checkout/onepagecheckout', '', true); |
||
| 216 | |||
| 217 | $this->load->model('extension/extension'); |
||
| 218 | |||
| 219 | $data['modules'] = array(); |
||
| 220 | |||
| 221 | $files = glob(SR_APPLICATION . '/controller/extension/total/*.php'); |
||
| 222 | |||
| 223 | if ($files) { |
||
| 224 | foreach ($files as $file) { |
||
| 225 | $result = $this->load->controller('extension/total/' . basename($file, '.php')); |
||
| 226 | |||
| 227 | if ($result) { |
||
| 228 | $data['modules'][] = $result; |
||
| 229 | } |
||
| 230 | } |
||
| 231 | } |
||
| 232 | |||
| 233 | $data['column'] = $this->load->controller('common/column'); |
||
| 234 | |||
| 235 | $data['content_top'] = $this->load->controller('common/content_top'); |
||
| 236 | $data['content_bottom'] = $this->load->controller('common/content_bottom'); |
||
| 237 | $data['footer'] = $this->load->controller('common/footer'); |
||
| 238 | $data['header'] = $this->load->controller('common/header'); |
||
| 239 | |||
| 240 | $this->response->setOutput($this->load->view('checkout/cart', $data)); |
||
| 241 | } else { |
||
| 242 | $data['heading_title'] = $this->language->get('heading_title'); |
||
| 243 | |||
| 244 | $data['text_error'] = $this->language->get('text_empty'); |
||
| 245 | $data['text_go_back'] = $this->language->get('text_go_back'); |
||
| 246 | $data['text_get_back'] = $this->language->get('text_get_back'); |
||
| 247 | |||
| 248 | $data['button_continue'] = $this->language->get('button_continue'); |
||
| 249 | |||
| 250 | $data['continue'] = $this->url->link('common/home'); |
||
| 251 | |||
| 252 | unset($this->session->data['success']); |
||
| 253 | |||
| 254 | $data['column'] = $this->load->controller('common/column'); |
||
| 255 | |||
| 256 | $data['content_top'] = $this->load->controller('common/content_top'); |
||
| 257 | $data['content_bottom'] = $this->load->controller('common/content_bottom'); |
||
| 258 | $data['footer'] = $this->load->controller('common/footer'); |
||
| 259 | $data['header'] = $this->load->controller('common/header'); |
||
| 260 | |||
| 261 | $this->response->setOutput($this->load->view('error/not_found', $data)); |
||
| 262 | } |
||
| 463 |
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.