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