Conditions | 51 |
Paths | > 20000 |
Total Lines | 298 |
Code Lines | 201 |
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 |
||
269 | protected function getForm() |
||
270 | { |
||
271 | $data['heading_title'] = $this->language->get('heading_title'); |
||
272 | |||
273 | $data['text_form'] = !isset($this->request->get['category_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); |
||
274 | $data['text_none'] = $this->language->get('text_none'); |
||
275 | $data['text_default'] = $this->language->get('text_default'); |
||
276 | $data['text_enabled'] = $this->language->get('text_enabled'); |
||
277 | $data['text_disabled'] = $this->language->get('text_disabled'); |
||
278 | |||
279 | $data['entry_name'] = $this->language->get('entry_name'); |
||
280 | $data['entry_description'] = $this->language->get('entry_description'); |
||
281 | $data['entry_description_bottom'] = $this->language->get('entry_description_bottom'); |
||
282 | $data['entry_meta_title'] = $this->language->get('entry_meta_title'); |
||
283 | $data['entry_meta_h1'] = $this->language->get('entry_meta_h1'); |
||
284 | $data['entry_meta_description'] = $this->language->get('entry_meta_description'); |
||
285 | $data['entry_keyword'] = $this->language->get('entry_keyword'); |
||
286 | $data['entry_parent'] = $this->language->get('entry_parent'); |
||
287 | $data['entry_filter'] = $this->language->get('entry_filter'); |
||
288 | $data['entry_image'] = $this->language->get('entry_image'); |
||
289 | $data['entry_top'] = $this->language->get('entry_top'); |
||
290 | $data['entry_column'] = $this->language->get('entry_column'); |
||
291 | $data['entry_sort_order'] = $this->language->get('entry_sort_order'); |
||
292 | $data['entry_status'] = $this->language->get('entry_status'); |
||
293 | $data['entry_noindex'] = $this->language->get('entry_noindex'); |
||
294 | $data['entry_layout'] = $this->language->get('entry_layout'); |
||
295 | $data['entry_related_wb'] = $this->language->get('entry_related_wb'); |
||
296 | $data['entry_related_article'] = $this->language->get('entry_related_article'); |
||
297 | |||
298 | $data['help_filter'] = $this->language->get('help_filter'); |
||
299 | $data['help_keyword'] = $this->language->get('help_keyword'); |
||
300 | $data['help_top'] = $this->language->get('help_top'); |
||
301 | $data['help_column'] = $this->language->get('help_column'); |
||
302 | $data['help_noindex'] = $this->language->get('help_noindex'); |
||
303 | |||
304 | $data['button_save'] = $this->language->get('button_save'); |
||
305 | $data['button_cancel'] = $this->language->get('button_cancel'); |
||
306 | |||
307 | $data['tab_general'] = $this->language->get('tab_general'); |
||
308 | $data['tab_data'] = $this->language->get('tab_data'); |
||
309 | $data['tab_related'] = $this->language->get('tab_related'); |
||
310 | $data['tab_design'] = $this->language->get('tab_design'); |
||
311 | |||
312 | if (isset($this->error['warning'])) { |
||
313 | $data['error_warning'] = $this->error['warning']; |
||
314 | } else { |
||
315 | $data['error_warning'] = ''; |
||
316 | } |
||
317 | |||
318 | if (isset($this->error['name'])) { |
||
319 | $data['error_name'] = $this->error['name']; |
||
320 | } else { |
||
321 | $data['error_name'] = array(); |
||
322 | } |
||
323 | |||
324 | if (isset($this->error['meta_title'])) { |
||
325 | $data['error_meta_title'] = $this->error['meta_title']; |
||
326 | } else { |
||
327 | $data['error_meta_title'] = array(); |
||
328 | } |
||
329 | |||
330 | if (isset($this->error['meta_h1'])) { |
||
331 | $data['error_meta_h1'] = $this->error['meta_h1']; |
||
332 | } else { |
||
333 | $data['error_meta_h1'] = array(); |
||
334 | } |
||
335 | |||
336 | if (isset($this->error['keyword'])) { |
||
337 | $data['error_keyword'] = $this->error['keyword']; |
||
338 | } else { |
||
339 | $data['error_keyword'] = ''; |
||
340 | } |
||
341 | |||
342 | if (isset($this->error['parent'])) { |
||
343 | $data['error_parent'] = $this->error['parent']; |
||
344 | } else { |
||
345 | $data['error_parent'] = ''; |
||
346 | } |
||
347 | |||
348 | $url = ''; |
||
349 | |||
350 | if (isset($this->request->get['sort'])) { |
||
351 | $url .= '&sort=' . $this->request->get['sort']; |
||
352 | } |
||
353 | |||
354 | if (isset($this->request->get['order'])) { |
||
355 | $url .= '&order=' . $this->request->get['order']; |
||
356 | } |
||
357 | |||
358 | if (isset($this->request->get['page'])) { |
||
359 | $url .= '&page=' . $this->request->get['page']; |
||
360 | } |
||
361 | |||
362 | $data['breadcrumbs'] = array(); |
||
363 | |||
364 | $data['breadcrumbs'][] = array( |
||
365 | 'text' => $this->language->get('text_home'), |
||
366 | 'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], true) |
||
367 | ); |
||
368 | |||
369 | $data['breadcrumbs'][] = array( |
||
370 | 'text' => $this->language->get('heading_title'), |
||
371 | 'href' => $this->url->link('catalog/category', 'token=' . $this->session->data['token'] . $url, true) |
||
372 | ); |
||
373 | |||
374 | if (!isset($this->request->get['category_id'])) { |
||
375 | $data['action'] = $this->url->link('catalog/category/add', 'token=' . $this->session->data['token'] . $url, true); |
||
376 | } else { |
||
377 | $data['action'] = $this->url->link('catalog/category/edit', 'token=' . $this->session->data['token'] . '&category_id=' . $this->request->get['category_id'] . $url, true); |
||
378 | } |
||
379 | |||
380 | $data['cancel'] = $this->url->link('catalog/category', 'token=' . $this->session->data['token'] . $url, true); |
||
381 | |||
382 | if (isset($this->request->get['category_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { |
||
383 | $category_info = $this->model_catalog_category->getCategory($this->request->get['category_id']); |
||
384 | } |
||
385 | |||
386 | $data['token'] = $this->session->data['token']; |
||
387 | |||
388 | $this->load->model('localisation/language'); |
||
389 | |||
390 | $data['languages'] = $this->model_localisation_language->getLanguages(); |
||
391 | |||
392 | if (isset($this->request->post['category_description'])) { |
||
393 | $data['category_description'] = $this->request->post['category_description']; |
||
394 | } elseif (isset($this->request->get['category_id'])) { |
||
395 | $data['category_description'] = $this->model_catalog_category->getCategoryDescriptions($this->request->get['category_id']); |
||
396 | } else { |
||
397 | $data['category_description'] = array(); |
||
398 | } |
||
399 | |||
400 | $language_id = $this->config->get('config_language_id'); |
||
401 | if (isset($data['category_description'][$language_id]['name'])) { |
||
402 | $data['heading_title'] = $data['category_description'][$language_id]['name']; |
||
403 | } |
||
404 | |||
405 | if (isset($this->request->post['path'])) { |
||
406 | $data['path'] = $this->request->post['path']; |
||
407 | } elseif (!empty($category_info)) { |
||
408 | $data['path'] = $category_info['path']; |
||
409 | } else { |
||
410 | $data['path'] = ''; |
||
411 | } |
||
412 | |||
413 | if (isset($this->request->post['parent_id'])) { |
||
414 | $data['parent_id'] = $this->request->post['parent_id']; |
||
415 | } elseif (!empty($category_info)) { |
||
416 | $data['parent_id'] = $category_info['parent_id']; |
||
417 | } else { |
||
418 | $data['parent_id'] = 0; |
||
419 | } |
||
420 | |||
421 | $this->load->model('catalog/filter'); |
||
422 | |||
423 | if (isset($this->request->post['category_filter'])) { |
||
424 | $filters = $this->request->post['category_filter']; |
||
425 | } elseif (isset($this->request->get['category_id'])) { |
||
426 | $filters = $this->model_catalog_category->getCategoryFilters($this->request->get['category_id']); |
||
427 | } else { |
||
428 | $filters = array(); |
||
429 | } |
||
430 | |||
431 | $data['category_filters'] = array(); |
||
432 | |||
433 | foreach ($filters as $filter_id) { |
||
434 | $filter_info = $this->model_catalog_filter->getFilter($filter_id); |
||
435 | |||
436 | if ($filter_info) { |
||
437 | $data['category_filters'][] = array( |
||
438 | 'filter_id' => $filter_info['filter_id'], |
||
439 | 'name' => $filter_info['group'] . ' > ' . $filter_info['name'] |
||
440 | ); |
||
441 | } |
||
442 | } |
||
443 | |||
444 | if (isset($this->request->post['keyword'])) { |
||
445 | $data['keyword'] = $this->request->post['keyword']; |
||
446 | } elseif (!empty($category_info)) { |
||
447 | $data['keyword'] = $category_info['keyword']; |
||
448 | } else { |
||
449 | $data['keyword'] = ''; |
||
450 | } |
||
451 | |||
452 | if (isset($this->request->post['image'])) { |
||
453 | $data['image'] = $this->request->post['image']; |
||
454 | } elseif (!empty($category_info)) { |
||
455 | $data['image'] = $category_info['image']; |
||
456 | } else { |
||
457 | $data['image'] = ''; |
||
458 | } |
||
459 | |||
460 | |||
461 | |||
462 | if (isset($this->request->post['image']) && is_file($_SERVER['DOCUMENT_ROOT'] . '/public_html/assets/images/' . $this->request->post['image'])) { |
||
463 | $data['thumb'] = '/public_html/assets/images/' . $this->request->post['image']; |
||
464 | } elseif (!empty($category_info) && is_file($_SERVER['DOCUMENT_ROOT'] . '/public_html/assets/images/' . $category_info['image'])) { |
||
465 | $data['thumb'] = '/public_html/assets/images/' . $category_info['image']; |
||
466 | } else { |
||
467 | $data['thumb'] = '/public_html/assets/images/no_image.png'; |
||
468 | } |
||
469 | |||
470 | $data['placeholder'] = '/public_html/assets/images/no_image.png'; |
||
471 | |||
472 | if (isset($this->request->post['top'])) { |
||
473 | $data['top'] = $this->request->post['top']; |
||
474 | } elseif (!empty($category_info)) { |
||
475 | $data['top'] = $category_info['top']; |
||
476 | } else { |
||
477 | $data['top'] = 0; |
||
478 | } |
||
479 | |||
480 | if (isset($this->request->post['sort_order'])) { |
||
481 | $data['sort_order'] = $this->request->post['sort_order']; |
||
482 | } elseif (!empty($category_info)) { |
||
483 | $data['sort_order'] = $category_info['sort_order']; |
||
484 | } else { |
||
485 | $data['sort_order'] = 0; |
||
486 | } |
||
487 | |||
488 | if (isset($this->request->post['product_related'])) { |
||
489 | $products = $this->request->post['product_related']; |
||
490 | } elseif (isset($category_info)) { |
||
491 | $products = $this->model_catalog_category->getProductRelated($this->request->get['category_id']); |
||
492 | } else { |
||
493 | $products = array(); |
||
494 | } |
||
495 | |||
496 | $data['product_related'] = array(); |
||
497 | |||
498 | $this->load->model('catalog/product'); |
||
499 | |||
500 | foreach ($products as $product_id) { |
||
501 | $related_info = $this->model_catalog_product->getProduct($product_id); |
||
502 | |||
503 | if ($related_info) { |
||
504 | $data['product_related'][] = array( |
||
505 | 'product_id' => $related_info['product_id'], |
||
506 | 'name' => $related_info['name'] |
||
507 | ); |
||
508 | } |
||
509 | } |
||
510 | |||
511 | if (isset($this->request->post['article_related'])) { |
||
512 | $articles = $this->request->post['article_related']; |
||
513 | } elseif (isset($category_info)) { |
||
514 | $articles = $this->model_catalog_category->getArticleRelated($this->request->get['category_id']); |
||
515 | } else { |
||
516 | $articles = array(); |
||
517 | } |
||
518 | |||
519 | $data['article_related'] = array(); |
||
520 | |||
521 | $this->load->model('blog/article'); |
||
522 | |||
523 | foreach ($articles as $article_id) { |
||
524 | $related_info = $this->model_blog_article->getArticle($article_id); |
||
525 | |||
526 | if ($related_info) { |
||
527 | $data['article_related'][] = array( |
||
528 | 'article_id' => $related_info['article_id'], |
||
529 | 'name' => $related_info['name'] |
||
530 | ); |
||
531 | } |
||
532 | } |
||
533 | |||
534 | if (isset($this->request->post['status'])) { |
||
535 | $data['status'] = $this->request->post['status']; |
||
536 | } elseif (!empty($category_info)) { |
||
537 | $data['status'] = $category_info['status']; |
||
538 | } else { |
||
539 | $data['status'] = true; |
||
540 | } |
||
541 | |||
542 | if (isset($this->request->post['noindex'])) { |
||
543 | $data['noindex'] = $this->request->post['noindex']; |
||
544 | } elseif (!empty($category_info)) { |
||
545 | $data['noindex'] = $category_info['noindex']; |
||
546 | } else { |
||
547 | $data['noindex'] = 1; |
||
548 | } |
||
549 | |||
550 | if (isset($this->request->post['category_layout'])) { |
||
551 | $data['category_layout'] = $this->request->post['category_layout']; |
||
552 | } elseif (isset($this->request->get['category_id'])) { |
||
553 | $data['category_layout'] = $this->model_catalog_category->getCategoryLayouts($this->request->get['category_id']); |
||
554 | } else { |
||
555 | $data['category_layout'] = array(); |
||
556 | } |
||
557 | |||
558 | $this->load->model('design/layout'); |
||
559 | |||
560 | $data['layouts'] = $this->model_design_layout->getLayouts(); |
||
561 | |||
562 | $data['header'] = $this->load->controller('common/header'); |
||
563 | $data['column'] = $this->load->controller('common/column_left'); |
||
564 | $data['footer'] = $this->load->controller('common/footer'); |
||
565 | |||
566 | $this->response->setOutput($this->load->view('catalog/category_form', $data)); |
||
567 | } |
||
794 |
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.