| Conditions | 33 |
| Paths | > 20000 |
| Total Lines | 274 |
| Code Lines | 173 |
| 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('product/special'); |
||
| 28 | |||
| 29 | $this->load->model('catalog/product'); |
||
| 30 | |||
| 31 | |||
| 32 | |||
| 33 | if (isset($this->request->get['sort'])) { |
||
| 34 | $sort = $this->request->get['sort']; |
||
| 35 | $this->document->setRobots('noindex,follow'); |
||
| 36 | } else { |
||
| 37 | $sort = 'p.sort_order'; |
||
| 38 | } |
||
| 39 | |||
| 40 | if (isset($this->request->get['order'])) { |
||
| 41 | $order = $this->request->get['order']; |
||
| 42 | } else { |
||
| 43 | $order = 'ASC'; |
||
| 44 | } |
||
| 45 | |||
| 46 | if (isset($this->request->get['page'])) { |
||
| 47 | $page = $this->request->get['page']; |
||
| 48 | $this->document->setRobots('noindex,follow'); |
||
| 49 | } else { |
||
| 50 | $page = 1; |
||
| 51 | } |
||
| 52 | |||
| 53 | if (isset($this->request->get['limit'])) { |
||
| 54 | $limit = ((int)$this->request->get['limit'] > 100 ? 100 : (int)$this->request->get['limit']); |
||
| 55 | $this->document->setRobots('noindex,follow'); |
||
| 56 | } else { |
||
| 57 | $limit = $this->config->get('config_limit_store'); |
||
| 58 | } |
||
| 59 | |||
| 60 | if ($this->config->get('seomanager_meta_title_special')) { |
||
| 61 | $this->document->setTitle($this->config->get('seomanager_meta_title_special')); |
||
| 62 | } else { |
||
| 63 | $this->document->setTitle($this->language->get('heading_title')); |
||
| 64 | } |
||
| 65 | |||
| 66 | if ($this->config->get('seomanager_html_h1_special')) { |
||
| 67 | $data['heading_title'] = $this->config->get('seomanager_html_h1_special'); |
||
| 68 | } else { |
||
| 69 | $data['heading_title'] = $this->language->get('heading_title'); |
||
| 70 | } |
||
| 71 | |||
| 72 | if ($this->config->get('seomanager_meta_description_special')) { |
||
| 73 | $this->document->setDescription($this->config->get('seomanager_meta_description_special')); |
||
| 74 | } |
||
| 75 | |||
| 76 | $data['description'] = html_entity_decode(($this->config->get('seomanager_description_special')), ENT_QUOTES, 'UTF-8'); |
||
| 77 | |||
| 78 | $data['breadcrumbs'] = array(); |
||
| 79 | |||
| 80 | $data['breadcrumbs'][] = array( |
||
| 81 | 'text' => $this->language->get('text_home'), |
||
| 82 | 'href' => $this->url->link('common/home') |
||
| 83 | ); |
||
| 84 | |||
| 85 | $url = ''; |
||
| 86 | |||
| 87 | if (isset($this->request->get['sort'])) { |
||
| 88 | $url .= '&sort=' . $this->request->get['sort']; |
||
| 89 | } |
||
| 90 | |||
| 91 | if (isset($this->request->get['order'])) { |
||
| 92 | $url .= '&order=' . $this->request->get['order']; |
||
| 93 | } |
||
| 94 | |||
| 95 | if (isset($this->request->get['page'])) { |
||
| 96 | $url .= '&page=' . $this->request->get['page']; |
||
| 97 | } |
||
| 98 | |||
| 99 | if (isset($this->request->get['limit'])) { |
||
| 100 | $url .= '&limit=' . $this->request->get['limit']; |
||
| 101 | } |
||
| 102 | |||
| 103 | $data['breadcrumbs'][] = array( |
||
| 104 | 'text' => $this->language->get('heading_title'), |
||
| 105 | 'href' => $this->url->link('product/special', $url) |
||
| 106 | ); |
||
| 107 | |||
| 108 | $data['text_empty'] = $this->language->get('text_empty'); |
||
| 109 | $data['text_quantity'] = $this->language->get('text_quantity'); |
||
| 110 | $data['text_manufacturer'] = $this->language->get('text_manufacturer'); |
||
| 111 | $data['text_model'] = $this->language->get('text_model'); |
||
| 112 | $data['text_price'] = $this->language->get('text_price'); |
||
| 113 | $data['text_points'] = $this->language->get('text_points'); |
||
| 114 | $data['text_sort'] = $this->language->get('text_sort'); |
||
| 115 | $data['text_limit'] = $this->language->get('text_limit'); |
||
| 116 | $data['text_go_back'] = $this->language->get('text_go_back'); |
||
| 117 | |||
| 118 | $data['button_buy_it'] = $this->language->get('button_buy_it'); |
||
| 119 | $data['button_list'] = $this->language->get('button_list'); |
||
| 120 | $data['button_grid'] = $this->language->get('button_grid'); |
||
| 121 | $data['button_continue'] = $this->language->get('button_continue'); |
||
| 122 | |||
| 123 | $data['products'] = array(); |
||
| 124 | |||
| 125 | $filter_data = array( |
||
| 126 | 'sort' => $sort, |
||
| 127 | 'order' => $order, |
||
| 128 | 'start' => ($page - 1) * $limit, |
||
| 129 | 'limit' => $limit |
||
| 130 | ); |
||
| 131 | |||
| 132 | $product_total = $this->model_catalog_product->getTotalProductSpecials(); |
||
| 133 | |||
| 134 | $results = $this->model_catalog_product->getProductSpecials($filter_data); |
||
| 135 | |||
| 136 | foreach ($results as $result) { |
||
| 137 | if ($result['image']) { |
||
| 138 | $image = '/public_html/assets/images/' . $result['image']; |
||
| 139 | } else { |
||
| 140 | $image = '/public_html/assets/images/no_image.png'; |
||
| 141 | } |
||
| 142 | |||
| 143 | if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) { |
||
| 144 | $price = $this->currency->format($result['price'], $this->session->data['currency']); |
||
| 145 | } else { |
||
| 146 | $price = false; |
||
| 147 | } |
||
| 148 | |||
| 149 | if ((float)$result['special']) { |
||
| 150 | $special = $this->currency->format($result['special'], $this->session->data['currency']); |
||
| 151 | } else { |
||
| 152 | $special = false; |
||
| 153 | } |
||
| 154 | |||
| 155 | if ($result['description_mini']) { |
||
| 156 | $description = \voku\helper\UTF8::substr(strip_tags(html_entity_decode($result['description_mini'], ENT_QUOTES, 'UTF-8')), 0); |
||
| 157 | } else { |
||
| 158 | $description = \voku\helper\UTF8::substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get($this->config->get('config_theme') . '_product_description_length')) . '..'; |
||
| 159 | } |
||
| 160 | |||
| 161 | $stickers = $this->getStickers($result['product_id']); |
||
| 162 | |||
| 163 | $data['products'][] = array( |
||
| 164 | 'product_id' => $result['product_id'], |
||
| 165 | 'thumb' => $image, |
||
| 166 | 'name' => $result['name'], |
||
| 167 | 'description' => $description, |
||
| 168 | 'price' => $price, |
||
| 169 | 'special' => $special, |
||
| 170 | 'sticker' => $stickers, |
||
| 171 | 'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1, |
||
| 172 | 'href' => $this->url->link('product/product', 'product_id=' . $result['product_id'] . $url) |
||
| 173 | ); |
||
| 174 | } |
||
| 175 | |||
| 176 | $url = ''; |
||
| 177 | |||
| 178 | if (isset($this->request->get['limit'])) { |
||
| 179 | $url .= '&limit=' . $this->request->get['limit']; |
||
| 180 | } |
||
| 181 | |||
| 182 | $data['sorts'] = array(); |
||
| 183 | |||
| 184 | $data['sorts'][] = array( |
||
| 185 | 'text' => $this->language->get('text_default'), |
||
| 186 | 'value' => 'p.sort_order-ASC', |
||
| 187 | 'href' => $this->url->link('product/special', 'sort=p.sort_order&order=ASC' . $url) |
||
| 188 | ); |
||
| 189 | |||
| 190 | $data['sorts'][] = array( |
||
| 191 | 'text' => $this->language->get('text_name_asc'), |
||
| 192 | 'value' => 'pd.name-ASC', |
||
| 193 | 'href' => $this->url->link('product/special', 'sort=pd.name&order=ASC' . $url) |
||
| 194 | ); |
||
| 195 | |||
| 196 | $data['sorts'][] = array( |
||
| 197 | 'text' => $this->language->get('text_name_desc'), |
||
| 198 | 'value' => 'pd.name-DESC', |
||
| 199 | 'href' => $this->url->link('product/special', 'sort=pd.name&order=DESC' . $url) |
||
| 200 | ); |
||
| 201 | |||
| 202 | $data['sorts'][] = array( |
||
| 203 | 'text' => $this->language->get('text_price_asc'), |
||
| 204 | 'value' => 'ps.price-ASC', |
||
| 205 | 'href' => $this->url->link('product/special', 'sort=ps.price&order=ASC' . $url) |
||
| 206 | ); |
||
| 207 | |||
| 208 | $data['sorts'][] = array( |
||
| 209 | 'text' => $this->language->get('text_price_desc'), |
||
| 210 | 'value' => 'ps.price-DESC', |
||
| 211 | 'href' => $this->url->link('product/special', 'sort=ps.price&order=DESC' . $url) |
||
| 212 | ); |
||
| 213 | |||
| 214 | $data['sorts'][] = array( |
||
| 215 | 'text' => $this->language->get('text_model_asc'), |
||
| 216 | 'value' => 'p.model-ASC', |
||
| 217 | 'href' => $this->url->link('product/special', 'sort=p.model&order=ASC' . $url) |
||
| 218 | ); |
||
| 219 | |||
| 220 | $data['sorts'][] = array( |
||
| 221 | 'text' => $this->language->get('text_model_desc'), |
||
| 222 | 'value' => 'p.model-DESC', |
||
| 223 | 'href' => $this->url->link('product/special', 'sort=p.model&order=DESC' . $url) |
||
| 224 | ); |
||
| 225 | |||
| 226 | $url = ''; |
||
| 227 | |||
| 228 | if (isset($this->request->get['sort'])) { |
||
| 229 | $url .= '&sort=' . $this->request->get['sort']; |
||
| 230 | } |
||
| 231 | |||
| 232 | if (isset($this->request->get['order'])) { |
||
| 233 | $url .= '&order=' . $this->request->get['order']; |
||
| 234 | } |
||
| 235 | |||
| 236 | $data['limits'] = array(); |
||
| 237 | |||
| 238 | $limits = array_unique(array($this->config->get('config_limit_store'), 25, 50, 75, 100)); |
||
| 239 | |||
| 240 | sort($limits); |
||
| 241 | |||
| 242 | foreach ($limits as $value) { |
||
| 243 | $data['limits'][] = array( |
||
| 244 | 'text' => $value, |
||
| 245 | 'value' => $value, |
||
| 246 | 'href' => $this->url->link('product/special', $url . '&limit=' . $value) |
||
| 247 | ); |
||
| 248 | } |
||
| 249 | |||
| 250 | $url = ''; |
||
| 251 | |||
| 252 | if (isset($this->request->get['sort'])) { |
||
| 253 | $url .= '&sort=' . $this->request->get['sort']; |
||
| 254 | } |
||
| 255 | |||
| 256 | if (isset($this->request->get['order'])) { |
||
| 257 | $url .= '&order=' . $this->request->get['order']; |
||
| 258 | } |
||
| 259 | |||
| 260 | if (isset($this->request->get['limit'])) { |
||
| 261 | $url .= '&limit=' . $this->request->get['limit']; |
||
| 262 | } |
||
| 263 | |||
| 264 | $pagination = new \Divine\Engine\Library\Pagination(); |
||
| 265 | $pagination->total = $product_total; |
||
| 266 | $pagination->page = $page; |
||
| 267 | $pagination->limit = $limit; |
||
| 268 | $pagination->url = $this->url->link('product/special', $url . '&page={page}'); |
||
| 269 | |||
| 270 | $data['pagination'] = $pagination->render(); |
||
| 271 | |||
| 272 | $data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($product_total - $limit)) ? $product_total : ((($page - 1) * $limit) + $limit), $product_total, ceil($product_total / $limit)); |
||
| 273 | |||
| 274 | // http://googlewebmastercentral.blogspot.com/2011/09/pagination-with-relnext-and-relprev.html |
||
| 275 | if ($page == 1) { |
||
| 276 | $this->document->addLink($this->url->link('product/special', '', true), 'canonical'); |
||
| 277 | } elseif ($page == 2) { |
||
| 278 | $this->document->addLink($this->url->link('product/special', '', true), 'prev'); |
||
| 279 | } else { |
||
| 280 | $this->document->addLink($this->url->link('product/special', 'page=' . ($page - 1), true), 'prev'); |
||
| 281 | } |
||
| 282 | |||
| 283 | if ($limit && ceil($product_total / $limit) > $page) { |
||
| 284 | $this->document->addLink($this->url->link('product/special', 'page=' . ($page + 1), true), 'next'); |
||
| 285 | } |
||
| 286 | |||
| 287 | $data['sort'] = $sort; |
||
| 288 | $data['order'] = $order; |
||
| 289 | $data['limit'] = $limit; |
||
| 290 | |||
| 291 | $data['continue'] = $this->url->link('common/home'); |
||
| 292 | |||
| 293 | $data['content_top'] = $this->load->controller('common/content_top'); |
||
| 294 | $data['content_bottom'] = $this->load->controller('common/content_bottom'); |
||
| 295 | $data['footer'] = $this->load->controller('common/footer'); |
||
| 296 | $data['header'] = $this->load->controller('common/header'); |
||
| 297 | |||
| 298 | $this->response->setOutput($this->load->view('product/special', $data)); |
||
| 299 | } |
||
| 321 |
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.