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