| Conditions | 41 |
| Paths | > 20000 |
| Total Lines | 352 |
| Code Lines | 220 |
| 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 |
||
| 87 | public function info() |
||
| 88 | { |
||
| 89 | $this->load->language('product/manufacturer'); |
||
| 90 | |||
| 91 | $this->load->model('catalog/manufacturer'); |
||
| 92 | |||
| 93 | $this->load->model('catalog/product'); |
||
| 94 | |||
| 95 | |||
| 96 | |||
| 97 | if (isset($this->request->get['manufacturer_id'])) { |
||
| 98 | $manufacturer_id = (int) $this->request->get['manufacturer_id']; |
||
| 99 | } else { |
||
| 100 | $manufacturer_id = 0; |
||
| 101 | } |
||
| 102 | |||
| 103 | if (isset($this->request->get['sort'])) { |
||
| 104 | $sort = $this->request->get['sort']; |
||
| 105 | $this->document->setRobots('noindex,follow'); |
||
| 106 | } else { |
||
| 107 | $sort = 'p.sort_order'; |
||
| 108 | } |
||
| 109 | |||
| 110 | if (isset($this->request->get['order'])) { |
||
| 111 | $order = $this->request->get['order']; |
||
| 112 | } else { |
||
| 113 | $order = 'ASC'; |
||
| 114 | } |
||
| 115 | |||
| 116 | if (isset($this->request->get['page'])) { |
||
| 117 | $page = $this->request->get['page']; |
||
| 118 | $this->document->setRobots('noindex,follow'); |
||
| 119 | } else { |
||
| 120 | $page = 1; |
||
| 121 | } |
||
| 122 | |||
| 123 | if (isset($this->request->get['limit'])) { |
||
| 124 | $limit = ((int) $this->request->get['limit'] > 100 ? 100 : (int) $this->request->get['limit']); |
||
| 125 | $this->document->setRobots('noindex,follow'); |
||
| 126 | } else { |
||
| 127 | $limit = (int) $this->config->get('config_limit_store'); |
||
| 128 | } |
||
| 129 | |||
| 130 | $data['breadcrumbs'] = array(); |
||
| 131 | |||
| 132 | $data['breadcrumbs'][] = array( |
||
| 133 | 'text' => $this->language->get('text_home'), |
||
| 134 | 'href' => $this->url->link('common/home') |
||
| 135 | ); |
||
| 136 | |||
| 137 | $data['breadcrumbs'][] = array( |
||
| 138 | 'text' => $this->language->get('text_brand'), |
||
| 139 | 'href' => $this->url->link('product/manufacturer') |
||
| 140 | ); |
||
| 141 | |||
| 142 | $manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($manufacturer_id); |
||
| 143 | |||
| 144 | if ($manufacturer_info) { |
||
| 145 | if ($manufacturer_info['meta_title']) { |
||
| 146 | $this->document->setTitle($manufacturer_info['meta_title']); |
||
| 147 | } else { |
||
| 148 | $this->document->setTitle($manufacturer_info['name']); |
||
| 149 | } |
||
| 150 | |||
| 151 | if ($manufacturer_info['noindex'] <= 0) { |
||
| 152 | $this->document->setRobots('noindex,follow'); |
||
| 153 | } |
||
| 154 | |||
| 155 | if ($manufacturer_info['meta_h1']) { |
||
| 156 | $data['heading_title'] = $manufacturer_info['meta_h1']; |
||
| 157 | } else { |
||
| 158 | $data['heading_title'] = $manufacturer_info['name']; |
||
| 159 | } |
||
| 160 | |||
| 161 | $this->document->setDescription($manufacturer_info['meta_description']); |
||
| 162 | |||
| 163 | $data['description'] = html_entity_decode($manufacturer_info['description'], ENT_QUOTES, 'UTF-8'); |
||
| 164 | $data['description_bottom'] = html_entity_decode($manufacturer_info['description_bottom'], ENT_QUOTES, 'UTF-8'); |
||
| 165 | |||
| 166 | if ($manufacturer_info['image']) { |
||
| 167 | $data['thumb'] = '/public_html/assets/images/' . $manufacturer_info['image']; |
||
| 168 | } else { |
||
| 169 | $data['thumb'] = '/public_html/assets/images/no_image.png'; |
||
| 170 | } |
||
| 171 | |||
| 172 | $url = ''; |
||
| 173 | |||
| 174 | if (isset($this->request->get['sort'])) { |
||
| 175 | $url .= '&sort=' . $this->request->get['sort']; |
||
| 176 | } |
||
| 177 | |||
| 178 | if (isset($this->request->get['order'])) { |
||
| 179 | $url .= '&order=' . $this->request->get['order']; |
||
| 180 | } |
||
| 181 | |||
| 182 | if (isset($this->request->get['page'])) { |
||
| 183 | $url .= '&page=' . $this->request->get['page']; |
||
| 184 | } |
||
| 185 | |||
| 186 | if (isset($this->request->get['limit'])) { |
||
| 187 | $url .= '&limit=' . $this->request->get['limit']; |
||
| 188 | } |
||
| 189 | |||
| 190 | $data['breadcrumbs'][] = array( |
||
| 191 | 'text' => $manufacturer_info['name'], |
||
| 192 | 'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url) |
||
| 193 | ); |
||
| 194 | |||
| 195 | $data['text_empty'] = $this->language->get('text_empty'); |
||
| 196 | $data['text_quantity'] = $this->language->get('text_quantity'); |
||
| 197 | $data['text_manufacturer'] = $this->language->get('text_manufacturer'); |
||
| 198 | $data['text_model'] = $this->language->get('text_model'); |
||
| 199 | $data['text_price'] = $this->language->get('text_price'); |
||
| 200 | $data['text_points'] = $this->language->get('text_points'); |
||
| 201 | $data['text_sort'] = $this->language->get('text_sort'); |
||
| 202 | $data['text_limit'] = $this->language->get('text_limit'); |
||
| 203 | $data['text_go_back'] = $this->language->get('text_go_back'); |
||
| 204 | |||
| 205 | $data['button_buy_it'] = $this->language->get('button_buy_it'); |
||
| 206 | $data['button_continue'] = $this->language->get('button_continue'); |
||
| 207 | $data['button_list'] = $this->language->get('button_list'); |
||
| 208 | $data['button_grid'] = $this->language->get('button_grid'); |
||
| 209 | |||
| 210 | $data['products'] = array(); |
||
| 211 | |||
| 212 | $filter_data = array( |
||
| 213 | 'filter_manufacturer_id' => $manufacturer_id, |
||
| 214 | 'sort' => $sort, |
||
| 215 | 'order' => $order, |
||
| 216 | 'start' => ($page - 1) * $limit, |
||
| 217 | 'limit' => $limit |
||
| 218 | ); |
||
| 219 | |||
| 220 | $product_total = $this->model_catalog_product->getTotalProducts($filter_data); |
||
| 221 | |||
| 222 | $results = $this->model_catalog_product->getProducts($filter_data); |
||
| 223 | |||
| 224 | foreach ($results as $result) { |
||
| 225 | if ($result['image']) { |
||
| 226 | $image = '/public_html/assets/images/' . $result['image']; |
||
| 227 | } else { |
||
| 228 | $image = '/public_html/assets/images/no_image.png'; |
||
| 229 | } |
||
| 230 | |||
| 231 | if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) { |
||
| 232 | $price = $this->currency->format($result['price'], $this->session->data['currency']); |
||
| 233 | } else { |
||
| 234 | $price = false; |
||
| 235 | } |
||
| 236 | |||
| 237 | if ((float) $result['special']) { |
||
| 238 | $special = $this->currency->format($result['special'], $this->session->data['currency']); |
||
| 239 | } else { |
||
| 240 | $special = false; |
||
| 241 | } |
||
| 242 | |||
| 243 | if ($result['description_mini']) { |
||
| 244 | $description = \voku\helper\UTF8::substr(strip_tags(html_entity_decode($result['description_mini'], ENT_QUOTES, 'UTF-8')), 0); |
||
| 245 | } else { |
||
| 246 | $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')) . '..'; |
||
| 247 | } |
||
| 248 | |||
| 249 | $stickers = $this->getStickers($result['product_id']); |
||
| 250 | |||
| 251 | $data['products'][] = array( |
||
| 252 | 'product_id' => $result['product_id'], |
||
| 253 | 'thumb' => $image, |
||
| 254 | 'name' => $result['name'], |
||
| 255 | 'description' => $description, |
||
| 256 | 'price' => $price, |
||
| 257 | 'special' => $special, |
||
| 258 | 'sticker' => $stickers, |
||
| 259 | 'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1, |
||
| 260 | 'href' => $this->url->link('product/product', 'manufacturer_id=' . $result['manufacturer_id'] . '&product_id=' . $result['product_id'] . $url) |
||
| 261 | ); |
||
| 262 | } |
||
| 263 | |||
| 264 | $url = ''; |
||
| 265 | |||
| 266 | if (isset($this->request->get['limit'])) { |
||
| 267 | $url .= '&limit=' . $this->request->get['limit']; |
||
| 268 | } |
||
| 269 | |||
| 270 | $data['sorts'] = array(); |
||
| 271 | |||
| 272 | $data['sorts'][] = array( |
||
| 273 | 'text' => $this->language->get('text_default'), |
||
| 274 | 'value' => 'p.sort_order-ASC', |
||
| 275 | 'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.sort_order&order=ASC' . $url) |
||
| 276 | ); |
||
| 277 | |||
| 278 | $data['sorts'][] = array( |
||
| 279 | 'text' => $this->language->get('text_name_asc'), |
||
| 280 | 'value' => 'pd.name-ASC', |
||
| 281 | 'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=pd.name&order=ASC' . $url) |
||
| 282 | ); |
||
| 283 | |||
| 284 | $data['sorts'][] = array( |
||
| 285 | 'text' => $this->language->get('text_name_desc'), |
||
| 286 | 'value' => 'pd.name-DESC', |
||
| 287 | 'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=pd.name&order=DESC' . $url) |
||
| 288 | ); |
||
| 289 | |||
| 290 | $data['sorts'][] = array( |
||
| 291 | 'text' => $this->language->get('text_price_asc'), |
||
| 292 | 'value' => 'p.price-ASC', |
||
| 293 | 'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.price&order=ASC' . $url) |
||
| 294 | ); |
||
| 295 | |||
| 296 | $data['sorts'][] = array( |
||
| 297 | 'text' => $this->language->get('text_price_desc'), |
||
| 298 | 'value' => 'p.price-DESC', |
||
| 299 | 'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.price&order=DESC' . $url) |
||
| 300 | ); |
||
| 301 | |||
| 302 | $data['sorts'][] = array( |
||
| 303 | 'text' => $this->language->get('text_model_asc'), |
||
| 304 | 'value' => 'p.model-ASC', |
||
| 305 | 'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.model&order=ASC' . $url) |
||
| 306 | ); |
||
| 307 | |||
| 308 | $data['sorts'][] = array( |
||
| 309 | 'text' => $this->language->get('text_model_desc'), |
||
| 310 | 'value' => 'p.model-DESC', |
||
| 311 | 'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&sort=p.model&order=DESC' . $url) |
||
| 312 | ); |
||
| 313 | |||
| 314 | $url = ''; |
||
| 315 | |||
| 316 | if (isset($this->request->get['sort'])) { |
||
| 317 | $url .= '&sort=' . $this->request->get['sort']; |
||
| 318 | } |
||
| 319 | |||
| 320 | if (isset($this->request->get['order'])) { |
||
| 321 | $url .= '&order=' . $this->request->get['order']; |
||
| 322 | } |
||
| 323 | |||
| 324 | $data['limits'] = array(); |
||
| 325 | |||
| 326 | $limits = array_unique(array($this->config->get('config_limit_store'), 25, 50, 75, 100)); |
||
| 327 | |||
| 328 | sort($limits); |
||
| 329 | |||
| 330 | foreach ($limits as $value) { |
||
| 331 | $data['limits'][] = array( |
||
| 332 | 'text' => $value, |
||
| 333 | 'value' => $value, |
||
| 334 | 'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url . '&limit=' . $value) |
||
| 335 | ); |
||
| 336 | } |
||
| 337 | |||
| 338 | $url = ''; |
||
| 339 | |||
| 340 | if (isset($this->request->get['sort'])) { |
||
| 341 | $url .= '&sort=' . $this->request->get['sort']; |
||
| 342 | } |
||
| 343 | |||
| 344 | if (isset($this->request->get['order'])) { |
||
| 345 | $url .= '&order=' . $this->request->get['order']; |
||
| 346 | } |
||
| 347 | |||
| 348 | if (isset($this->request->get['limit'])) { |
||
| 349 | $url .= '&limit=' . $this->request->get['limit']; |
||
| 350 | } |
||
| 351 | |||
| 352 | $pagination = new \Divine\Engine\Library\Pagination(); |
||
| 353 | $pagination->total = $product_total; |
||
| 354 | $pagination->page = $page; |
||
| 355 | $pagination->limit = $limit; |
||
| 356 | $pagination->url = $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url . '&page={page}'); |
||
| 357 | |||
| 358 | $data['pagination'] = $pagination->render(); |
||
| 359 | |||
| 360 | $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)); |
||
| 361 | |||
| 362 | // http://googlewebmastercentral.blogspot.com/2011/09/pagination-with-relnext-and-relprev.html |
||
| 363 | if ($page == 1) { |
||
| 364 | $this->document->addLink($this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'], true), 'canonical'); |
||
| 365 | } elseif ($page == 2) { |
||
| 366 | $this->document->addLink($this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'], true), 'prev'); |
||
| 367 | } else { |
||
| 368 | $this->document->addLink($this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url . '&page=' . ($page - 1), true), 'prev'); |
||
| 369 | } |
||
| 370 | |||
| 371 | if ($limit && ceil($product_total / $limit) > $page) { |
||
| 372 | $this->document->addLink($this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url . '&page=' . ($page + 1), true), 'next'); |
||
| 373 | } |
||
| 374 | |||
| 375 | $data['sort'] = $sort; |
||
| 376 | $data['order'] = $order; |
||
| 377 | $data['limit'] = $limit; |
||
| 378 | |||
| 379 | $data['continue'] = $this->url->link('common/home'); |
||
| 380 | |||
| 381 | $data['column'] = $this->load->controller('common/column'); |
||
| 382 | |||
| 383 | $data['content_top'] = $this->load->controller('common/content_top'); |
||
| 384 | $data['content_bottom'] = $this->load->controller('common/content_bottom'); |
||
| 385 | $data['footer'] = $this->load->controller('common/footer'); |
||
| 386 | $data['header'] = $this->load->controller('common/header'); |
||
| 387 | |||
| 388 | $this->response->setOutput($this->load->view('product/manufacturer_info', $data)); |
||
| 389 | } else { |
||
| 390 | $url = ''; |
||
| 391 | |||
| 392 | if (isset($this->request->get['manufacturer_id'])) { |
||
| 393 | $url .= '&manufacturer_id=' . $this->request->get['manufacturer_id']; |
||
| 394 | } |
||
| 395 | |||
| 396 | if (isset($this->request->get['sort'])) { |
||
| 397 | $url .= '&sort=' . $this->request->get['sort']; |
||
| 398 | } |
||
| 399 | |||
| 400 | if (isset($this->request->get['order'])) { |
||
| 401 | $url .= '&order=' . $this->request->get['order']; |
||
| 402 | } |
||
| 403 | |||
| 404 | if (isset($this->request->get['page'])) { |
||
| 405 | $url .= '&page=' . $this->request->get['page']; |
||
| 406 | } |
||
| 407 | |||
| 408 | if (isset($this->request->get['limit'])) { |
||
| 409 | $url .= '&limit=' . $this->request->get['limit']; |
||
| 410 | } |
||
| 411 | |||
| 412 | $data['breadcrumbs'][] = array( |
||
| 413 | 'text' => $this->language->get('text_error'), |
||
| 414 | 'href' => $this->url->link('product/manufacturer/info', $url) |
||
| 415 | ); |
||
| 416 | |||
| 417 | $this->document->setTitle($this->language->get('text_error')); |
||
| 418 | |||
| 419 | $data['heading_title'] = $this->language->get('text_error'); |
||
| 420 | |||
| 421 | $data['text_error'] = $this->language->get('text_error'); |
||
| 422 | $data['text_go_back'] = $this->language->get('text_go_back'); |
||
| 423 | $data['text_get_back'] = $this->language->get('text_get_back'); |
||
| 424 | |||
| 425 | $data['button_continue'] = $this->language->get('button_continue'); |
||
| 426 | |||
| 427 | $data['continue'] = $this->url->link('common/home'); |
||
| 428 | |||
| 429 | $this->response->addHeader($this->request->server['SERVER_PROTOCOL'] . ' 404 Not Found'); |
||
| 430 | |||
| 431 | $data['header'] = $this->load->controller('common/header'); |
||
| 432 | $data['footer'] = $this->load->controller('common/footer'); |
||
| 433 | $data['column'] = $this->load->controller('common/column'); |
||
| 434 | |||
| 435 | $data['content_top'] = $this->load->controller('common/content_top'); |
||
| 436 | $data['content_bottom'] = $this->load->controller('common/content_bottom'); |
||
| 437 | |||
| 438 | $this->response->setOutput($this->load->view('error/not_found', $data)); |
||
| 439 | } |
||
| 462 |
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.