| Conditions | 8 |
| Paths | 32 |
| Total Lines | 55 |
| Code Lines | 32 |
| Lines | 13 |
| Ratio | 23.64 % |
| 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 |
||
| 59 | function xoops_module_install_xfguestbook(XoopsModule $module) |
||
| 60 | { |
||
| 61 | include_once dirname(dirname(dirname(__DIR__))) . '/mainfile.php'; |
||
| 62 | include_once dirname(__DIR__) . '/include/config.php'; |
||
| 63 | |||
| 64 | if (!isset($moduleDirName)) { |
||
| 65 | $moduleDirName = basename(dirname(__DIR__)); |
||
| 66 | } |
||
| 67 | |||
| 68 | if (false !== ($moduleHelper = Xmf\Module\Helper::getHelper($moduleDirName))) { |
||
| 69 | } else { |
||
| 70 | $moduleHelper = Xmf\Module\Helper::getHelper('system'); |
||
| 71 | } |
||
| 72 | |||
| 73 | // Load language files |
||
| 74 | $moduleHelper->loadLanguage('admin'); |
||
| 75 | $moduleHelper->loadLanguage('modinfo'); |
||
| 76 | |||
| 77 | $configurator = new ModuleConfigurator(); |
||
| 78 | $classUtil = ucfirst($moduleDirName) . 'Util'; |
||
| 79 | if (!class_exists($classUtil)) { |
||
| 80 | xoops_load('util', $moduleDirName); |
||
| 81 | } |
||
| 82 | |||
| 83 | // default Permission Settings ---------------------- |
||
| 84 | global $xoopsModule; |
||
| 85 | $moduleId = $xoopsModule->getVar('mid'); |
||
| 86 | $moduleId2 = $moduleHelper->getModule()->mid(); |
||
| 87 | $gpermHandler = xoops_getHandler('groupperm'); |
||
| 88 | // access rights ------------------------------------------ |
||
| 89 | $gpermHandler->addRight($moduleDirName . '_approve', 1, XOOPS_GROUP_ADMIN, $moduleId); |
||
| 90 | $gpermHandler->addRight($moduleDirName . '_submit', 1, XOOPS_GROUP_ADMIN, $moduleId); |
||
| 91 | $gpermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ADMIN, $moduleId); |
||
| 92 | $gpermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_USERS, $moduleId); |
||
| 93 | $gpermHandler->addRight($moduleDirName . '_view', 1, XOOPS_GROUP_ANONYMOUS, $moduleId); |
||
| 94 | |||
| 95 | // --- CREATE FOLDERS --------------- |
||
| 96 | View Code Duplication | if (count($configurator->uploadFolders) > 0) { |
|
| 97 | // foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
||
| 98 | foreach (array_keys($configurator->uploadFolders) as $i) { |
||
| 99 | $classUtil::createFolder($configurator->uploadFolders[$i]); |
||
| 100 | } |
||
| 101 | } |
||
| 102 | |||
| 103 | // --- COPY blank.png FILES --------------- |
||
| 104 | View Code Duplication | if (count($configurator->blankFiles) > 0) { |
|
| 105 | $file = __DIR__ . '/../assets/images/blank.png'; |
||
| 106 | foreach (array_keys($configurator->blankFiles) as $i) { |
||
| 107 | $dest = $configurator->blankFiles[$i] . '/blank.png'; |
||
| 108 | $classUtil::copyFile($file, $dest); |
||
| 109 | } |
||
| 110 | } |
||
| 111 | |||
| 112 | return true; |
||
| 113 | } |
||
| 114 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: