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