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