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