Conditions | 58 |
Total Lines | 346 |
Code Lines | 230 |
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 |
||
466 | protected function getForm() |
||
467 | { |
||
468 | $data['heading_title'] = $this->language->get('heading_title'); |
||
469 | |||
470 | $data['text_form'] = !isset($this->request->get['article_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); |
||
471 | $data['text_enabled'] = $this->language->get('text_enabled'); |
||
472 | $data['text_disabled'] = $this->language->get('text_disabled'); |
||
473 | $data['text_none'] = $this->language->get('text_none'); |
||
474 | $data['text_yes'] = $this->language->get('text_yes'); |
||
475 | $data['text_no'] = $this->language->get('text_no'); |
||
476 | $data['text_default'] = $this->language->get('text_default'); |
||
477 | $data['text_select'] = $this->language->get('text_select'); |
||
478 | $data['entry_name'] = $this->language->get('entry_name'); |
||
479 | $data['entry_description'] = $this->language->get('entry_description'); |
||
480 | $data['entry_meta_title'] = $this->language->get('entry_meta_title'); |
||
481 | $data['entry_meta_h1'] = $this->language->get('entry_meta_h1'); |
||
482 | $data['entry_meta_description'] = $this->language->get('entry_meta_description'); |
||
483 | $data['entry_keyword'] = $this->language->get('entry_keyword'); |
||
484 | $data['entry_image'] = $this->language->get('entry_image'); |
||
485 | $data['entry_download'] = $this->language->get('entry_download'); |
||
486 | $data['entry_category'] = $this->language->get('entry_category'); |
||
487 | $data['entry_main_category'] = $this->language->get('entry_main_category'); |
||
488 | $data['entry_related'] = $this->language->get('entry_related'); |
||
489 | $data['entry_related_product'] = $this->language->get('entry_related_product'); |
||
490 | $data['entry_sort_order'] = $this->language->get('entry_sort_order'); |
||
491 | $data['entry_status'] = $this->language->get('entry_status'); |
||
492 | $data['entry_noindex'] = $this->language->get('entry_noindex'); |
||
493 | $data['entry_tag'] = $this->language->get('entry_tag'); |
||
494 | $data['entry_layout'] = $this->language->get('entry_layout'); |
||
495 | |||
496 | $data['help_keyword'] = $this->language->get('help_keyword'); |
||
497 | $data['help_category'] = $this->language->get('help_category'); |
||
498 | $data['help_download'] = $this->language->get('help_download'); |
||
499 | $data['help_related'] = $this->language->get('help_related'); |
||
500 | $data['help_related_product'] = $this->language->get('help_related_product'); |
||
501 | $data['help_tag'] = $this->language->get('help_tag'); |
||
502 | $data['help_noindex'] = $this->language->get('help_noindex'); |
||
503 | |||
504 | $data['button_save'] = $this->language->get('button_save'); |
||
505 | $data['button_cancel'] = $this->language->get('button_cancel'); |
||
506 | $data['button_image_add'] = $this->language->get('button_image_add'); |
||
507 | $data['button_remove'] = $this->language->get('button_remove'); |
||
508 | |||
509 | $data['tab_general'] = $this->language->get('tab_general'); |
||
510 | $data['tab_data'] = $this->language->get('tab_data'); |
||
511 | $data['tab_links'] = $this->language->get('tab_links'); |
||
512 | $data['tab_design'] = $this->language->get('tab_design'); |
||
513 | |||
514 | if (isset($this->error['warning'])) { |
||
515 | $data['error_warning'] = $this->error['warning']; |
||
516 | } else { |
||
517 | $data['error_warning'] = ''; |
||
518 | } |
||
519 | |||
520 | if (isset($this->error['name'])) { |
||
521 | $data['error_name'] = $this->error['name']; |
||
522 | } else { |
||
523 | $data['error_name'] = array(); |
||
524 | } |
||
525 | |||
526 | if (isset($this->error['meta_title'])) { |
||
527 | $data['error_meta_title'] = $this->error['meta_title']; |
||
528 | } else { |
||
529 | $data['error_meta_title'] = array(); |
||
530 | } |
||
531 | |||
532 | if (isset($this->error['meta_h1'])) { |
||
533 | $data['error_meta_h1'] = $this->error['meta_h1']; |
||
534 | } else { |
||
535 | $data['error_meta_h1'] = array(); |
||
536 | } |
||
537 | |||
538 | if (isset($this->error['keyword'])) { |
||
539 | $data['error_keyword'] = $this->error['keyword']; |
||
540 | } else { |
||
541 | $data['error_keyword'] = ''; |
||
542 | } |
||
543 | |||
544 | $url = ''; |
||
545 | |||
546 | if (isset($this->request->get['filter_name'])) { |
||
547 | $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); |
||
548 | } |
||
549 | |||
550 | if (isset($this->request->get['filter_status'])) { |
||
551 | $url .= '&filter_status=' . $this->request->get['filter_status']; |
||
552 | } |
||
553 | |||
554 | if (isset($this->request->get['filter_noindex'])) { |
||
555 | $url .= '&filter_noindex=' . $this->request->get['filter_noindex']; |
||
556 | } |
||
557 | |||
558 | if (isset($this->request->get['sort'])) { |
||
559 | $url .= '&sort=' . $this->request->get['sort']; |
||
560 | } |
||
561 | |||
562 | if (isset($this->request->get['order'])) { |
||
563 | $url .= '&order=' . $this->request->get['order']; |
||
564 | } |
||
565 | |||
566 | if (isset($this->request->get['page'])) { |
||
567 | $url .= '&page=' . $this->request->get['page']; |
||
568 | } |
||
569 | |||
570 | $data['breadcrumbs'] = array(); |
||
571 | |||
572 | $data['breadcrumbs'][] = array( |
||
573 | 'text' => $this->language->get('text_home'), |
||
574 | 'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], true) |
||
575 | ); |
||
576 | |||
577 | $data['breadcrumbs'][] = array( |
||
578 | 'text' => $this->language->get('heading_title'), |
||
579 | 'href' => $this->url->link('blog/article', 'token=' . $this->session->data['token'] . $url, true) |
||
580 | ); |
||
581 | |||
582 | if (!isset($this->request->get['article_id'])) { |
||
583 | $data['action'] = $this->url->link('blog/article/add', 'token=' . $this->session->data['token'] . $url, true); |
||
584 | } else { |
||
585 | $data['action'] = $this->url->link('blog/article/edit', 'token=' . $this->session->data['token'] . '&article_id=' . $this->request->get['article_id'] . $url, true); |
||
586 | } |
||
587 | |||
588 | $data['cancel'] = $this->url->link('blog/article', 'token=' . $this->session->data['token'] . $url, true); |
||
589 | |||
590 | if (isset($this->request->get['article_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { |
||
591 | $article_info = $this->model_blog_article->getArticle($this->request->get['article_id']); |
||
592 | } |
||
593 | |||
594 | $data['token'] = $this->session->data['token']; |
||
595 | |||
596 | $this->load->model('localisation/language'); |
||
597 | |||
598 | $data['languages'] = $this->model_localisation_language->getLanguages(); |
||
599 | |||
600 | if (isset($this->request->post['article_description'])) { |
||
601 | $data['article_description'] = $this->request->post['article_description']; |
||
602 | } elseif (isset($this->request->get['article_id'])) { |
||
603 | $data['article_description'] = $this->model_blog_article->getArticleDescriptions($this->request->get['article_id']); |
||
604 | } else { |
||
605 | $data['article_description'] = array(); |
||
606 | } |
||
607 | |||
608 | $language_id = $this->config->get('config_language_id'); |
||
609 | if (isset($data['article_description'][$language_id]['name'])) { |
||
610 | $data['heading_title'] = $data['article_description'][$language_id]['name']; |
||
611 | } |
||
612 | |||
613 | if (isset($this->request->post['image'])) { |
||
614 | $data['image'] = $this->request->post['image']; |
||
615 | } elseif (!empty($article_info)) { |
||
616 | $data['image'] = $article_info['image']; |
||
617 | } else { |
||
618 | $data['image'] = ''; |
||
619 | } |
||
620 | |||
621 | |||
622 | |||
623 | if (isset($this->request->post['image']) && is_file($_SERVER['DOCUMENT_ROOT'] . '/public_html/assets/images/' . $this->request->post['image'])) { |
||
624 | $data['thumb'] = '/public_html/assets/images/' . $this->request->post['image']; |
||
625 | } elseif (!empty($article_info) && is_file($_SERVER['DOCUMENT_ROOT'] . '/public_html/assets/images/' . $article_info['image'])) { |
||
626 | $data['thumb'] = '/public_html/assets/images/' . $article_info['image']; |
||
627 | } else { |
||
628 | $data['thumb'] = '/public_html/assets/images/no_image.png'; |
||
629 | } |
||
630 | |||
631 | $data['placeholder'] = '/public_html/assets/images/no_image.png'; |
||
632 | |||
633 | if (isset($this->request->post['keyword'])) { |
||
634 | $data['keyword'] = $this->request->post['keyword']; |
||
635 | } elseif (!empty($article_info)) { |
||
636 | $data['keyword'] = $article_info['keyword']; |
||
637 | } else { |
||
638 | $data['keyword'] = ''; |
||
639 | } |
||
640 | |||
641 | if (isset($this->request->post['sort_order'])) { |
||
642 | $data['sort_order'] = $this->request->post['sort_order']; |
||
643 | } elseif (!empty($article_info)) { |
||
644 | $data['sort_order'] = $article_info['sort_order']; |
||
645 | } else { |
||
646 | $data['sort_order'] = 1; |
||
647 | } |
||
648 | |||
649 | if (isset($this->request->post['status'])) { |
||
650 | $data['status'] = $this->request->post['status']; |
||
651 | } elseif (!empty($article_info)) { |
||
652 | $data['status'] = $article_info['status']; |
||
653 | } else { |
||
654 | $data['status'] = true; |
||
655 | } |
||
656 | |||
657 | if (isset($this->request->post['noindex'])) { |
||
658 | $data['noindex'] = $this->request->post['noindex']; |
||
659 | } elseif (!empty($article_info)) { |
||
660 | $data['noindex'] = $article_info['noindex']; |
||
661 | } else { |
||
662 | $data['noindex'] = 1; |
||
663 | } |
||
664 | |||
665 | // Categories |
||
666 | $this->load->model('blog/category'); |
||
667 | |||
668 | $categories = $this->model_blog_category->getAllCategories(); |
||
669 | |||
670 | $data['categories'] = $this->model_blog_category->getCategories($categories); |
||
671 | |||
672 | if (isset($this->request->post['main_blog_category_id'])) { |
||
673 | $data['main_blog_category_id'] = $this->request->post['main_blog_category_id']; |
||
674 | } elseif (isset($article_info)) { |
||
675 | $data['main_blog_category_id'] = $this->model_blog_article->getArticleMainCategoryId($this->request->get['article_id']); |
||
676 | } else { |
||
677 | $data['main_blog_category_id'] = 0; |
||
678 | } |
||
679 | |||
680 | if (isset($this->request->post['article_blog_category'])) { |
||
681 | $categories = $this->request->post['article_blog_category']; |
||
682 | } elseif (isset($this->request->get['article_id'])) { |
||
683 | $categories = $this->model_blog_article->getArticleCategories($this->request->get['article_id']); |
||
684 | } else { |
||
685 | $categories = array(); |
||
686 | } |
||
687 | |||
688 | $data['article_categories'] = array(); |
||
689 | |||
690 | foreach ($categories as $blog_category_id) { |
||
691 | $category_info = $this->model_blog_category->getCategory($blog_category_id); |
||
692 | |||
693 | if ($category_info) { |
||
694 | $data['article_categories'][] = array( |
||
695 | 'blog_category_id' => $category_info['blog_category_id'], |
||
696 | 'name' => ($category_info['path']) ? $category_info['path'] . ' > ' . $category_info['name'] : $category_info['name'] |
||
697 | ); |
||
698 | } |
||
699 | } |
||
700 | |||
701 | // Images |
||
702 | if (isset($this->request->post['article_image'])) { |
||
703 | $article_images = $this->request->post['article_image']; |
||
704 | } elseif (isset($this->request->get['article_id'])) { |
||
705 | $article_images = $this->model_blog_article->getArticleImages($this->request->get['article_id']); |
||
706 | } else { |
||
707 | $article_images = array(); |
||
708 | } |
||
709 | |||
710 | $data['article_images'] = array(); |
||
711 | |||
712 | foreach ($article_images as $article_image) { |
||
713 | if (is_file($_SERVER['DOCUMENT_ROOT'] . '/public_html/assets/images/' . $article_image['image'])) { |
||
714 | $image = $article_image['image']; |
||
715 | $thumb = $article_image['image']; |
||
716 | } else { |
||
717 | $image = ''; |
||
718 | $thumb = 'no_image.png'; |
||
719 | } |
||
720 | |||
721 | $data['article_images'][] = array( |
||
722 | 'image' => $image, |
||
723 | 'thumb' => '/public_html/assets/images/' . $thumb, |
||
724 | 'sort_order' => $article_image['sort_order'] |
||
725 | ); |
||
726 | } |
||
727 | |||
728 | // Downloads |
||
729 | $this->load->model('catalog/download'); |
||
730 | |||
731 | if (isset($this->request->post['article_download'])) { |
||
732 | $article_downloads = $this->request->post['article_download']; |
||
733 | } elseif (isset($this->request->get['article_id'])) { |
||
734 | $article_downloads = $this->model_blog_article->getArticleDownloads($this->request->get['article_id']); |
||
735 | } else { |
||
736 | $article_downloads = array(); |
||
737 | } |
||
738 | |||
739 | $data['article_downloads'] = array(); |
||
740 | |||
741 | foreach ($article_downloads as $download_id) { |
||
742 | $download_info = $this->model_catalog_download->getDownload($download_id); |
||
743 | |||
744 | if ($download_info) { |
||
745 | $data['article_downloads'][] = array( |
||
746 | 'download_id' => $download_info['download_id'], |
||
747 | 'name' => $download_info['name'] |
||
748 | ); |
||
749 | } |
||
750 | } |
||
751 | |||
752 | if (isset($this->request->post['article_related'])) { |
||
753 | $articles = $this->request->post['article_related']; |
||
754 | } elseif (isset($this->request->get['article_id'])) { |
||
755 | $articles = $this->model_blog_article->getArticleRelated($this->request->get['article_id']); |
||
756 | } else { |
||
757 | $articles = array(); |
||
758 | } |
||
759 | |||
760 | $data['article_relateds'] = array(); |
||
761 | |||
762 | foreach ($articles as $article_id) { |
||
763 | $related_info = $this->model_blog_article->getArticle($article_id); |
||
764 | |||
765 | if ($related_info) { |
||
766 | $data['article_relateds'][] = array( |
||
767 | 'article_id' => $related_info['article_id'], |
||
768 | 'name' => $related_info['name'] |
||
769 | ); |
||
770 | } |
||
771 | } |
||
772 | |||
773 | if (isset($this->request->post['product_related'])) { |
||
774 | $products = $this->request->post['product_related']; |
||
775 | } elseif (isset($article_info)) { |
||
776 | $products = $this->model_blog_article->getProductRelated($this->request->get['article_id']); |
||
777 | } else { |
||
778 | $products = array(); |
||
779 | } |
||
780 | |||
781 | $data['product_relateds'] = array(); |
||
782 | $this->load->model('catalog/product'); |
||
783 | |||
784 | foreach ($products as $product_id) { |
||
785 | $product_info = $this->model_catalog_product->getProduct($product_id); |
||
786 | |||
787 | if ($product_info) { |
||
788 | $data['product_relateds'][] = array( |
||
789 | 'product_id' => $product_info['product_id'], |
||
790 | 'name' => $product_info['name'] |
||
791 | ); |
||
792 | } |
||
793 | } |
||
794 | |||
795 | if (isset($this->request->post['article_layout'])) { |
||
796 | $data['article_layout'] = $this->request->post['article_layout']; |
||
797 | } elseif (isset($this->request->get['article_id'])) { |
||
798 | $data['article_layout'] = $this->model_blog_article->getArticleLayouts($this->request->get['article_id']); |
||
799 | } else { |
||
800 | $data['article_layout'] = array(); |
||
801 | } |
||
802 | |||
803 | $this->load->model('design/layout'); |
||
804 | |||
805 | $data['layouts'] = $this->model_design_layout->getLayouts(); |
||
806 | |||
807 | $data['header'] = $this->load->controller('common/header'); |
||
808 | $data['column'] = $this->load->controller('common/column_left'); |
||
809 | $data['footer'] = $this->load->controller('common/footer'); |
||
810 | |||
811 | $this->response->setOutput($this->load->view('blog/article_form', $data)); |
||
812 | } |
||
982 |
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.