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