Conditions | 14 |
Paths | 216 |
Total Lines | 75 |
Code Lines | 49 |
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 |
||
54 | public static function generateSitemap() |
||
55 | { |
||
56 | $block = []; |
||
57 | $moduleDirName = \basename(\dirname(__DIR__)); |
||
|
|||
58 | /** @internal can't use Helper since function called during install |
||
59 | * $helper = \Xmf\Module\Helper::getHelper($moduleDirName); |
||
60 | * $pluginHandler = $helper->getHandler('Plugin', $moduleDirName); |
||
61 | */ |
||
62 | // xoops_load('plugin', $moduleDirName); |
||
63 | \xoops_load('XoopsModuleConfig'); |
||
64 | // Get list of modules admin wants to hide from xsitemap |
||
65 | $invisibleDirnames = empty($GLOBALS['xoopsModuleConfig']['invisible_dirnames']) ? ['xsitemap'] : \explode(',', $GLOBALS['xoopsModuleConfig']['invisible_dirnames'] . ',xsitemap'); |
||
66 | $invisibleDirnames = \array_map('\trim', $invisibleDirnames); |
||
67 | $invisibleDirnames = \array_map('\mb_strtolower', $invisibleDirnames); |
||
68 | // Get the mid for any of these modules if they're active and hasmain (visible frontside) |
||
69 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
70 | $moduleHandler = \xoops_getHandler('module'); |
||
71 | $invisibleMidArray = []; |
||
72 | foreach ($invisibleDirnames as $hiddenDir) { |
||
73 | $criteria = new \CriteriaCompo(new \Criteria('hasmain', 1)); |
||
74 | $criteria->add(new \Criteria('isactive', 1)); |
||
75 | $criteria->add(new \Criteria('name', $hiddenDir)); |
||
76 | $modObj = $moduleHandler->getByDirname($hiddenDir); |
||
77 | if (false !== $modObj && $modObj instanceof \XoopsModule) { |
||
78 | $invisibleMidArray[] = $modObj->mid(); |
||
79 | } |
||
80 | } |
||
81 | // Where user has permissions |
||
82 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||
83 | $grouppermHandler = \xoops_getHandler('groupperm'); |
||
84 | $groups = ($GLOBALS['xoopsUser'] instanceof \XoopsUser) ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS; |
||
85 | $readAllowed = $grouppermHandler->getItemIds('module_read', $groups); |
||
86 | $filteredMids = \array_diff($readAllowed, $invisibleMidArray); |
||
87 | $pluginHandler = Helper::getInstance()->getHandler('Plugin'); |
||
88 | $criteria = new \CriteriaCompo(new \Criteria('hasmain', 1)); |
||
89 | $criteria->add(new \Criteria('isactive', 1)); |
||
90 | if (\count($filteredMids) > 0) { |
||
91 | $criteria->add(new \Criteria('mid', '(' . \implode(',', $filteredMids) . ')', 'IN')); |
||
92 | } |
||
93 | $modules = $moduleHandler->getObjects($criteria, true); |
||
94 | $criteria = new \CriteriaCompo(); |
||
95 | $criteria->setSort('plugin_id'); |
||
96 | $criteria->order = 'ASC'; |
||
97 | $pluginObjArray = $pluginHandler->getAll($criteria); |
||
98 | /** @var array $sublinks */ |
||
99 | foreach ($modules as $mid => $modObj) { |
||
100 | $sublinks = $modObj->subLink(); |
||
101 | $modDirName = $modObj->getVar('dirname', 'n'); |
||
102 | $block['modules'][$mid] = [ |
||
103 | 'id' => $mid, |
||
104 | 'name' => $modObj->getVar('name'), |
||
105 | 'directory' => $modDirName, |
||
106 | 'sublinks' => [], |
||
107 | // init the sublinks array |
||
108 | ]; |
||
109 | // Now 'patch' the sublink to include module path |
||
110 | if (\count($sublinks) > 0) { |
||
111 | foreach ($sublinks as $sublink) { |
||
112 | $block['modules'][$mid]['sublinks'][] = [ |
||
113 | 'name' => $sublink['name'], |
||
114 | 'url' => $GLOBALS['xoops']->url("www/modules/{$modDirName}/{$sublink['url']}"), |
||
115 | ]; |
||
116 | } |
||
117 | } |
||
118 | foreach ($pluginObjArray as $pObj) { |
||
119 | if ((0 == $pObj->getVar('topic_pid')) && \in_array($pObj->getVar('plugin_mod_table'), (array)$modObj->getInfo('tables'))) { |
||
120 | $objVars = $pObj->getValues(); |
||
121 | if (1 == $objVars['plugin_online']) { |
||
122 | $tmpMap = self::getSitemap($objVars['plugin_mod_table'], $objVars['plugin_cat_id'], $objVars['plugin_cat_pid'], $objVars['plugin_cat_name'], $objVars['plugin_call'], $objVars['plugin_weight'], $objVars['plugin_where']); |
||
123 | $block['modules'][$mid]['parent'] = $tmpMap['parent'] ?? null; |
||
124 | } |
||
125 | } |
||
126 | } |
||
127 | } |
||
128 | return $block; |
||
129 | } |
||
249 |