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