| Conditions | 12 |
| Paths | 8 |
| Total Lines | 73 |
| Code Lines | 50 |
| 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 |
||
| 27 | function b_oledrion_category_show($options) |
||
| 28 | { |
||
| 29 | global $xoTheme; |
||
| 30 | $block = []; |
||
| 31 | require_once XOOPS_ROOT_PATH . '/modules/oledrion/include/common.php'; |
||
| 32 | $xoTheme->addStylesheet(OLEDRION_URL . 'assets/css/oledrion.css'); |
||
| 33 | |||
| 34 | $block['nostock_msg'] = Oledrion\Utility::getModuleOption('nostock_msg'); |
||
| 35 | |||
| 36 | if (0 == (int)$options[0]) { |
||
| 37 | // Catégories selon la page en cours |
||
| 38 | $block['block_option'] = 0; |
||
| 39 | if (!isset($GLOBALS['current_category']) || -1 == $GLOBALS['current_category']) { |
||
| 40 | return false; |
||
| 41 | } |
||
| 42 | $cat_cid = (int)$GLOBALS['current_category']; |
||
| 43 | require_once XOOPS_ROOT_PATH . '/modules/oledrion/include/common.php'; |
||
| 44 | |||
| 45 | if ($cat_cid > 0) { |
||
| 46 | require_once XOOPS_ROOT_PATH . '/class/tree.php'; |
||
| 47 | $tbl_categories = $tblChilds = $tbl_tmp = []; |
||
| 48 | $tbl_categories = $categoryHandler->getAllCategories(new Oledrion\Parameters()); |
||
| 49 | $mytree = new Oledrion\XoopsObjectTree($tbl_categories, 'cat_cid', 'cat_pid'); |
||
| 50 | $tblChilds = $mytree->getAllChild($cat_cid); |
||
| 51 | //$tblChilds = array_reverse($tblChilds); |
||
| 52 | foreach ($tblChilds as $item) { |
||
| 53 | $tbl_tmp[] = "<a href='" . $item->getLink() . "' title='" . Oledrion\Utility::makeHrefTitle($item->getVar('cat_title')) . "'>" . $item->getVar('cat_title') . '</a>'; |
||
| 54 | } |
||
| 55 | $block['block_categories'] = $tbl_tmp; |
||
| 56 | |||
| 57 | $category = null; |
||
| 58 | if ($cat_cid > 0) { |
||
| 59 | $category = $categoryHandler->get($cat_cid); |
||
| 60 | if (is_object($category)) { |
||
| 61 | $block['block_current_category'] = $category->toArray(); |
||
| 62 | } |
||
| 63 | } |
||
| 64 | } else { |
||
| 65 | // On est à la racine, on n'affiche donc que les catégories mères |
||
| 66 | $tbl_categories = []; |
||
| 67 | $criteria = new \Criteria('cat_pid', 0, '='); |
||
| 68 | $criteria->setSort('cat_title'); |
||
| 69 | $tbl_categories = $categoryHandler->getObjects($criteria, true); |
||
| 70 | foreach ($tbl_categories as $item) { |
||
| 71 | $tbl_tmp[] = "<a href='" . $item->getLink() . "' title='" . Oledrion\Utility::makeHrefTitle($item->getVar('cat_title')) . "'>" . $item->getVar('cat_title') . '</a>'; |
||
| 72 | } |
||
| 73 | $block['block_categories'] = $tbl_tmp; |
||
| 74 | } |
||
| 75 | } elseif (1 == (int)$options[0]) { |
||
| 76 | // Affichage classique |
||
| 77 | $block['block_option'] = 1; |
||
| 78 | require_once XOOPS_ROOT_PATH . '/modules/oledrion/include/common.php'; |
||
| 79 | // require_once OLEDRION_PATH . 'class/tree.php'; |
||
| 80 | $tbl_categories = $categoryHandler->getAllCategories(new Oledrion\Parameters()); |
||
| 81 | $mytree = new Oledrion\XoopsObjectTree($tbl_categories, 'cat_cid', 'cat_pid'); |
||
| 82 | $jump = OLEDRION_URL . 'category.php?cat_cid='; |
||
| 83 | $additional = "onchange='location=\"" . $jump . "\"+this.options[this.selectedIndex].value'"; |
||
| 84 | $cat_cid = 0; |
||
| 85 | if (isset($GLOBALS['current_category']) && -1 != $GLOBALS['current_category']) { |
||
| 86 | $cat_cid = (int)$GLOBALS['current_category']; |
||
| 87 | } |
||
| 88 | |||
| 89 | $select0 = $mytree->makeSelectElement('cat_cid', 'cat_title', '-', $cat_cid, false, 0, '', $additional); |
||
| 90 | $htmlSelect = $select0->render(); |
||
| 91 | |||
| 92 | $block['htmlSelect'] = $htmlSelect; |
||
| 93 | } else { |
||
| 94 | // Affichage de toute l'arborescence, dépliée |
||
| 95 | $block['block_option'] = 2; |
||
| 96 | $block['liMenu'] = $categoryHandler->getUlMenu('category_title'); |
||
| 97 | } |
||
| 98 | |||
| 99 | return $block; |
||
| 100 | } |
||
| 146 |