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