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