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