| Conditions | 11 |
| Paths | 42 |
| Total Lines | 68 |
| Code Lines | 43 |
| 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\Mymenus\Plugins\Dynamic; |
||
| 55 | protected static function getModuleMenus($module, $pid) |
||
| 56 | { |
||
| 57 | global $xoopsModule; |
||
| 58 | static $id = -1; |
||
| 59 | /** @var \XoopsModules\Mymenus\Helper $helper */ |
||
| 60 | $helper = \XoopsModules\Mymenus\Helper::getInstance(); |
||
| 61 | |||
| 62 | |||
| 63 | $ret = []; |
||
| 64 | //Sanitizing $module |
||
| 65 | if (preg_match('/[^a-z0-9\\/\\\\_.:-]/i', $module)) { |
||
| 66 | return $ret; |
||
| 67 | } |
||
| 68 | |||
| 69 | $path = "modules/{$module}"; |
||
| 70 | $file = $GLOBALS['xoops']->path("{$path}/xoops_version.php"); |
||
| 71 | |||
| 72 | if (!file_exists($file)) { |
||
| 73 | return $ret; |
||
| 74 | } |
||
| 75 | $helper->loadLanguage('modinfo'); |
||
| 76 | |||
| 77 | |||
| 78 | $overwrite = false; |
||
| 79 | if (true === $force) { //can set to false for debug |
||
| 80 | if (!($xoopsModule instanceof \XoopsModule) || ($xoopsModule->getVar('dirname') != $module)) { |
||
| 81 | // @TODO: check the following 2 statements, they're basically just assigns - is this intended? |
||
| 82 | $_xoopsModule = ($xoopsModule instanceof \XoopsModule) ? $xoopsModule : $xoopsModule; |
||
| 83 | $_xoopsModuleConfig = is_object($xoopsModuleConfig) ? $xoopsModuleConfig : $xoopsModuleConfig; |
||
| 84 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
| 85 | $moduleHandler = xoops_getHandler('module'); |
||
| 86 | $xoopsModule = $moduleHandler->getByDirname($module); |
||
| 87 | $GLOBALS['xoopsModule'] = $xoopsModule; |
||
| 88 | if ($xoopsModule instanceof \XoopsModule) { |
||
| 89 | /** @var \XoopsConfigHandler $configHandler */ |
||
| 90 | $configHandler = xoops_getHandler('config'); |
||
| 91 | $xoopsModuleConfig = $configHandler->getConfigsByCat(0, $xoopsModule->getVar('mid')); |
||
| 92 | $GLOBALS['xoopsModuleConfig'] = $xoopsModuleConfig; |
||
| 93 | } |
||
| 94 | $overwrite = true; |
||
| 95 | } |
||
| 96 | } |
||
| 97 | $modversion['sub'] = []; |
||
| 98 | require $file; |
||
| 99 | |||
| 100 | /** @var \XoopsModules\Mymenus\LinksHandler $linksHandler */ |
||
| 101 | $linksHandler = $helper->getHandler('Links'); |
||
| 102 | foreach ($modversion['sub'] as $links) { |
||
| 103 | $obj = $linksHandler->create(); |
||
| 104 | $obj->setVars([ |
||
| 105 | 'title' => $links['name'], |
||
| 106 | 'alt_title' => $links['name'], |
||
| 107 | 'link' => $GLOBALS['xoops']->url("{$path}/{$links['url']}"), |
||
| 108 | 'id' => $id, |
||
| 109 | 'pid' => (int)$pid |
||
| 110 | ]); |
||
| 111 | $ret[] = $obj->getValues(); |
||
| 112 | $id--; |
||
| 113 | } |
||
| 114 | |||
| 115 | if ($overwrite) { |
||
| 116 | $xoopsModule = $_xoopsModule; |
||
| 117 | $GLOBALS['xoopsModule'] = $xoopsModule; |
||
| 118 | $xoopsModuleConfig = $_xoopsModuleConfig; |
||
| 119 | $GLOBALS['xoopsModuleConfig'] = $xoopsModuleConfig; |
||
| 120 | } |
||
| 121 | |||
| 122 | return $ret; |
||
| 123 | } |
||
| 125 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.