| Conditions | 42 | 
| Paths | > 20000 | 
| Total Lines | 222 | 
| Code Lines | 145 | 
| 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 namespace XoopsModules\Smartobject; | ||
| 588 | public function render($fetchOnly = false, $debug = false) | ||
| 589 |     { | ||
| 590 | require_once XOOPS_ROOT_PATH . '/class/template.php'; | ||
| 591 | |||
| 592 | $this->_tpl = new \XoopsTpl(); | ||
| 593 | |||
| 594 | /** | ||
| 595 | * We need access to the vars of the SmartObject for a few things in the table creation. | ||
| 596 | * Since we may not have a SmartObject to look into now, let's create one for this purpose | ||
| 597 | * and we will free it after | ||
| 598 | */ | ||
| 599 | $this->_tempObject = $this->_objectHandler->create(); | ||
| 600 | |||
| 601 | $this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? (int)$_GET['start' . $this->_objectHandler->keyName] : 0); | ||
| 602 | |||
| 603 | $this->setSortOrder(); | ||
| 604 | |||
| 605 |         if (!$this->_isTree) { | ||
| 606 | $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_limitsel', '15'); | ||
| 607 |         } else { | ||
| 608 | $this->_limitsel = 'all'; | ||
| 609 | } | ||
| 610 | |||
| 611 | $this->_limitsel = isset($_POST['limitsel']) ? $_POST['limitsel'] : $this->_limitsel; | ||
| 612 | Smartobject\Utility::setCookieVar($_SERVER['PHP_SELF'] . '_limitsel', $this->_limitsel); | ||
| 613 | $limitsArray = $this->getLimitsArray(); | ||
| 614 | $this->_criteria->setLimit($this->_limitsel); | ||
| 615 | |||
| 616 | $this->_filtersel = isset($_GET['filtersel']) ? $_GET['filtersel'] : $this->getDefaultFilter(); | ||
| 617 | $this->_filtersel = isset($_POST['filtersel']) ? $_POST['filtersel'] : $this->_filtersel; | ||
| 618 | Smartobject\Utility::setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); | ||
| 619 | $filtersArray = $this->getFiltersArray(); | ||
| 620 | |||
| 621 |         if ($filtersArray) { | ||
| 622 |             $this->_tpl->assign('smartobject_optionssel_filtersArray', $filtersArray); | ||
| 623 | } | ||
| 624 | |||
| 625 | // Check if the selected filter is defined and if so, create the selfilter2 | ||
| 626 |         if (isset($this->_filterseloptions[$this->_filtersel])) { | ||
| 627 | // check if method associate with this filter exists in the handler | ||
| 628 |             if (is_array($this->_filterseloptions[$this->_filtersel])) { | ||
| 629 | $filter = $this->_filterseloptions[$this->_filtersel]; | ||
| 630 | $this->_criteria->add($filter['criteria']); | ||
| 631 |             } else { | ||
| 632 |                 if (method_exists($this->_objectHandler, $this->_filterseloptions[$this->_filtersel])) { | ||
| 633 | |||
| 634 | // then we will create the selfilter2 options by calling this method | ||
| 635 | $method = $this->_filterseloptions[$this->_filtersel]; | ||
| 636 | $this->_filtersel2options = $this->_objectHandler->$method(); | ||
| 637 | |||
| 638 | $this->_filtersel2 = isset($_GET['filtersel2']) ? $_GET['filtersel2'] : $this->getDefaultFilter2(); | ||
| 639 | $this->_filtersel2 = isset($_POST['filtersel2']) ? $_POST['filtersel2'] : $this->_filtersel2; | ||
| 640 | |||
| 641 | $filters2Array = $this->getFilters2Array(); | ||
| 642 |                     $this->_tpl->assign('smartobject_optionssel_filters2Array', $filters2Array); | ||
| 643 | |||
| 644 | Smartobject\Utility::setCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); | ||
| 645 |                     if ('default' !== $this->_filtersel2) { | ||
| 646 | $this->_criteria->add(new \Criteria($this->_filtersel, $this->_filtersel2)); | ||
| 647 | } | ||
| 648 | } | ||
| 649 | } | ||
| 650 | } | ||
| 651 | // Check if we have a quicksearch | ||
| 652 | |||
| 653 |         if (isset($_POST['quicksearch_' . $this->_id]) && '' != $_POST['quicksearch_' . $this->_id]) { | ||
| 654 | $quicksearch_criteria = new \CriteriaCompo(); | ||
| 655 |             if (is_array($this->_quickSearch['fields'])) { | ||
| 656 |                 foreach ($this->_quickSearch['fields'] as $v) { | ||
| 657 | $quicksearch_criteria->add(new \Criteria($v, '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'), 'OR'); | ||
| 658 | } | ||
| 659 |             } else { | ||
| 660 | $quicksearch_criteria->add(new \Criteria($this->_quickSearch['fields'], '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE')); | ||
| 661 | } | ||
| 662 | $this->_criteria->add($quicksearch_criteria); | ||
| 663 | } | ||
| 664 | |||
| 665 | $this->_objects = $this->fetchObjects($debug); | ||
| 666 | |||
| 667 | require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; | ||
| 668 |         if ($this->_criteria->getLimit() > 0) { | ||
| 669 | |||
| 670 | /** | ||
| 671 | * Geeting rid of the old params | ||
| 672 | * $new_get_array is an array containing the new GET parameters | ||
| 673 | */ | ||
| 674 | $new_get_array = []; | ||
| 675 | |||
| 676 | /** | ||
| 677 | * $params_of_the_options_sel is an array with all the parameters of the page | ||
| 678 | * but without the pagenave parameters. This array will be used in the | ||
| 679 | * OptionsSelection | ||
| 680 | */ | ||
| 681 | $params_of_the_options_sel = []; | ||
| 682 | |||
| 683 | $not_needed_params = ['sortsel', 'limitsel', 'ordersel', 'start' . $this->_objectHandler->keyName]; | ||
| 684 |             foreach ($_GET as $k => $v) { | ||
| 685 |                 if (!in_array($k, $not_needed_params)) { | ||
| 686 | $new_get_array[] = "$k=$v"; | ||
| 687 | $params_of_the_options_sel[] = "$k=$v"; | ||
| 688 | } | ||
| 689 | } | ||
| 690 | |||
| 691 | /** | ||
| 692 | * Adding the new params of the pagenav | ||
| 693 | */ | ||
| 694 | $new_get_array[] = 'sortsel=' . $this->_sortsel; | ||
| 695 | $new_get_array[] = 'ordersel=' . $this->_ordersel; | ||
| 696 | $new_get_array[] = 'limitsel=' . $this->_limitsel; | ||
| 697 |             $otherParams     = implode('&', $new_get_array); | ||
| 698 | |||
| 699 | $pagenav = new \XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start' . $this->_objectHandler->keyName, $otherParams); | ||
| 700 |             $this->_tpl->assign('smartobject_pagenav', $pagenav->renderNav()); | ||
| 701 | } | ||
| 702 | $this->renderOptionSelection($limitsArray, $params_of_the_options_sel); | ||
| 703 | |||
| 704 | // retreive the current url and the query string | ||
| 705 | $current_urls = Smartobject\Utility::getCurrentUrls(); | ||
| 706 | $current_url = $current_urls['full_phpself']; | ||
| 707 | $query_string = $current_urls['querystring']; | ||
| 708 |         if ($query_string) { | ||
| 709 |             $query_string = str_replace('?', '', $query_string); | ||
| 710 | } | ||
| 711 |         $query_stringArray     = explode('&', $query_string); | ||
| 712 | $new_query_stringArray = []; | ||
| 713 |         foreach ($query_stringArray as $query_string) { | ||
| 714 |             if (false === strpos($query_string, 'sortsel') && false === strpos($query_string, 'ordersel')) { | ||
| 715 | $new_query_stringArray[] = $query_string; | ||
| 716 | } | ||
| 717 | } | ||
| 718 |         $new_query_string = implode('&', $new_query_stringArray); | ||
| 719 | |||
| 720 | $orderArray = []; | ||
| 721 | $orderArray['ASC']['image'] = 'desc.png'; | ||
| 722 | $orderArray['ASC']['neworder'] = 'DESC'; | ||
| 723 | $orderArray['DESC']['image'] = 'asc.png'; | ||
| 724 | $orderArray['DESC']['neworder'] = 'ASC'; | ||
| 725 | |||
| 726 | $aColumns = []; | ||
| 727 | |||
| 728 |         foreach ($this->_columns as $column) { | ||
| 729 | $qs_param = ''; | ||
| 730 | $aColumn = []; | ||
| 731 | $aColumn['width'] = $column->getWidth(); | ||
| 732 | $aColumn['align'] = $column->getAlign(); | ||
| 733 | $aColumn['key'] = $column->getKeyName(); | ||
| 734 |             if ('checked' === $column->_keyname) { | ||
| 735 | $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"' . ' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_' . $this->_id . ', \'selected_smartobjects\');">'; | ||
| 736 |             } elseif ($column->getCustomCaption()) { | ||
| 737 | $aColumn['caption'] = $column->getCustomCaption(); | ||
| 738 |             } else { | ||
| 739 | $aColumn['caption'] = isset($this->_tempObject->vars[$column->getKeyName()]['form_caption']) ? $this->_tempObject->vars[$column->getKeyName()]['form_caption'] : $column->getKeyName(); | ||
| 740 | } | ||
| 741 | // Are we doing a GET sort on this column ? | ||
| 742 | $getSort = (isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) | ||
| 743 | && $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] == $column->getKeyName()) | ||
| 744 | || ($this->_sortsel == $column->getKeyName()); | ||
| 745 | $order = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : 'DESC'; | ||
| 746 | |||
| 747 |             if (isset($_REQUEST['quicksearch_' . $this->_id]) && '' != $_REQUEST['quicksearch_' . $this->_id]) { | ||
| 748 | $qs_param = '&quicksearch_' . $this->_id . '=' . $_REQUEST['quicksearch_' . $this->_id]; | ||
| 749 | } | ||
| 750 |             if (!$this->_enableColumnsSorting || 'checked' === $column->_keyname || !$column->isSortable()) { | ||
| 751 | $aColumn['caption'] = $aColumn['caption']; | ||
| 752 |             } elseif ($getSort) { | ||
| 753 | $aColumn['caption'] = '<a href="' | ||
| 754 | . $current_url | ||
| 755 | . '?' | ||
| 756 | . $this->_objectHandler->_itemname | ||
| 757 | . '_' | ||
| 758 | . 'sortsel=' | ||
| 759 | . $column->getKeyName() | ||
| 760 | . '&' | ||
| 761 | . $this->_objectHandler->_itemname | ||
| 762 | . '_' | ||
| 763 | . 'ordersel=' | ||
| 764 | . $orderArray[$order]['neworder'] | ||
| 765 | . $qs_param | ||
| 766 | . '&' | ||
| 767 | . $new_query_string | ||
| 768 | . '">' | ||
| 769 | . $aColumn['caption'] | ||
| 770 | . ' <img src="' | ||
| 771 | . SMARTOBJECT_IMAGES_ACTIONS_URL | ||
| 772 | . $orderArray[$order]['image'] | ||
| 773 | . '" alt="ASC"></a>'; | ||
| 774 |             } else { | ||
| 775 | $aColumn['caption'] = '<a href="' . $current_url . '?' . $this->_objectHandler->_itemname . '_' . 'sortsel=' . $column->getKeyName() . '&' . $this->_objectHandler->_itemname . '_' . 'ordersel=ASC' . $qs_param . '&' . $new_query_string . '">' . $aColumn['caption'] . '</a>'; | ||
| 776 | } | ||
| 777 | $aColumns[] = $aColumn; | ||
| 778 | } | ||
| 779 |         $this->_tpl->assign('smartobject_columns', $aColumns); | ||
| 780 | |||
| 781 |         if ($this->_quickSearch) { | ||
| 782 |             $this->_tpl->assign('smartobject_quicksearch', $this->_quickSearch['caption']); | ||
| 783 | } | ||
| 784 | |||
| 785 | $this->createTableRows(); | ||
| 786 | |||
| 787 |         $this->_tpl->assign('smartobject_showFilterAndLimit', $this->_showFilterAndLimit); | ||
| 788 |         $this->_tpl->assign('smartobject_isTree', $this->_isTree); | ||
| 789 |         $this->_tpl->assign('smartobject_show_action_column_title', $this->_showActionsColumnTitle); | ||
| 790 |         $this->_tpl->assign('smartobject_table_header', $this->_tableHeader); | ||
| 791 |         $this->_tpl->assign('smartobject_table_footer', $this->_tableFooter); | ||
| 792 |         $this->_tpl->assign('smartobject_printer_friendly_page', $this->_printerFriendlyPage); | ||
| 793 |         $this->_tpl->assign('smartobject_user_side', $this->_userSide); | ||
| 794 |         $this->_tpl->assign('smartobject_has_actions', $this->_hasActions); | ||
| 795 |         $this->_tpl->assign('smartobject_head_css_class', $this->_head_css_class); | ||
| 796 |         $this->_tpl->assign('smartobject_actionButtons', $this->_actionButtons); | ||
| 797 |         $this->_tpl->assign('smartobject_introButtons', $this->_introButtons); | ||
| 798 |         $this->_tpl->assign('smartobject_id', $this->_id); | ||
| 799 |         if (!empty($this->_withSelectedActions)) { | ||
| 800 |             $this->_tpl->assign('smartobject_withSelectedActions', $this->_withSelectedActions); | ||
| 801 | } | ||
| 802 | |||
| 803 | $smartobjectTable_template = $this->_customTemplate ?: 'smartobject_smarttable_display.tpl'; | ||
| 804 |         if ($fetchOnly) { | ||
| 805 |             return $this->_tpl->fetch('db:' . $smartobjectTable_template); | ||
| 806 |         } else { | ||
| 807 |             $this->_tpl->display('db:' . $smartobjectTable_template); | ||
| 808 | } | ||
| 809 | } | ||
| 810 | |||
| 825 | 
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.