| Conditions | 19 |
| Paths | 33 |
| Total Lines | 79 |
| Code Lines | 39 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 60 | function xoops_module_update_xlanguage(\XoopsModule $module, $previousVersion = null) |
||
| 61 | { |
||
| 62 | $moduleDirName = \basename(\dirname(__DIR__)); |
||
| 63 | |||
| 64 | $utility = new Utility(); |
||
| 65 | $configurator = new Configurator(); |
||
| 66 | |||
| 67 | if ($previousVersion < 310) { |
||
| 68 | //delete old HTML templates |
||
| 69 | if (count($configurator->templateFolders) > 0) { |
||
| 70 | foreach ($configurator->templateFolders as $folder) { |
||
| 71 | $templateFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $folder); |
||
| 72 | if (is_dir($templateFolder)) { |
||
| 73 | $templateList = array_diff(scandir($templateFolder, SCANDIR_SORT_NONE), ['..', '.']); |
||
| 74 | if (is_array($templateList)) { |
||
| 75 | foreach ($templateList as $k => $v) { |
||
| 76 | $fileInfo = new \SplFileInfo($templateFolder . $v); |
||
| 77 | if ('html' === $fileInfo->getExtension() && 'index.html' !== $fileInfo->getFilename()) { |
||
| 78 | if (is_file($templateFolder . $v)) { |
||
| 79 | unlink($templateFolder . $v); |
||
| 80 | } |
||
| 81 | } |
||
| 82 | } |
||
| 83 | } |
||
| 84 | } |
||
| 85 | } |
||
| 86 | } |
||
| 87 | |||
| 88 | // --- DELETE OLD FILES --------------- |
||
| 89 | if (count($configurator->oldFiles) > 0) { |
||
| 90 | // foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
||
| 91 | foreach (array_keys($configurator->oldFiles) as $i) { |
||
| 92 | $tempFile = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFiles[$i]); |
||
| 93 | if (is_file($tempFile)) { |
||
| 94 | unlink($tempFile); |
||
| 95 | } |
||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 99 | // --- DELETE OLD FOLDERS --------------- |
||
| 100 | xoops_load('XoopsFile'); |
||
| 101 | if (count($configurator->oldFolders) > 0) { |
||
| 102 | // foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
||
| 103 | foreach (array_keys($configurator->oldFolders) as $i) { |
||
| 104 | $tempFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFolders[$i]); |
||
| 105 | /* @var XoopsObjectHandler $folderHandler */ |
||
| 106 | $folderHandler = XoopsFile::getHandler('folder', $tempFolder); |
||
| 107 | $folderHandler->delete($tempFolder); |
||
| 108 | } |
||
| 109 | } |
||
| 110 | |||
| 111 | // --- CREATE FOLDERS --------------- |
||
| 112 | if (count($configurator->uploadFolders) > 0) { |
||
| 113 | // foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
||
| 114 | foreach (array_keys($configurator->uploadFolders) as $i) { |
||
| 115 | $utility::createFolder($configurator->uploadFolders[$i]); |
||
| 116 | } |
||
| 117 | } |
||
| 118 | |||
| 119 | // --- COPY blank.png FILES --------------- |
||
| 120 | if (count($configurator->copyBlankFiles) > 0) { |
||
| 121 | $file = \dirname(__DIR__) . '/assets/images/blank.png'; |
||
| 122 | foreach (array_keys($configurator->copyBlankFiles) as $i) { |
||
| 123 | $dest = $configurator->copyBlankFiles[$i] . '/blank.png'; |
||
| 124 | $utility::copyFile($file, $dest); |
||
| 125 | } |
||
| 126 | } |
||
| 127 | |||
| 128 | //delete .html entries from the tpl table |
||
| 129 | $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . '\' AND `tpl_file` LIKE \'%.html%\''; |
||
| 130 | $GLOBALS['xoopsDB']->queryF($sql); |
||
| 131 | |||
| 132 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||
| 133 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
| 134 | |||
| 135 | return $grouppermHandler->deleteByModule($module->getVar('mid'), 'item_read'); |
||
| 136 | } |
||
| 137 | |||
| 138 | return true; |
||
| 139 | } |
||
| 140 |