Conditions | 14 |
Paths | 5 |
Total Lines | 60 |
Code Lines | 32 |
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 |
||
53 | function xoops_module_update_gbook(\XoopsModule $module, $previousVersion = null) |
||
54 | { |
||
55 | global $xoopsDB; |
||
56 | |||
57 | if ($previousVersion < 111) { |
||
58 | // delete old HTML template files ============================ |
||
59 | $templateDirectory = $GLOBALS['xoops']->path('modules/' . $module->getVar('dirname', 'n') . '/templates/'); |
||
60 | if (is_dir($templateDirectory)) { |
||
61 | $templateList = array_diff(scandir($templateDirectory, SCANDIR_SORT_NONE), ['..', '.']); |
||
62 | foreach ($templateList as $k => $v) { |
||
63 | $fileInfo = new \SplFileInfo($templateDirectory . $v); |
||
64 | if ('html' === $fileInfo->getExtension() && 'index.html' !== $fileInfo->getFilename()) { |
||
65 | if (is_file($templateDirectory . $v)) { |
||
66 | unlink($templateDirectory . $v); |
||
67 | } |
||
68 | } |
||
69 | } |
||
70 | } |
||
71 | // delete old block html template files ============================ |
||
72 | $templateDirectory = $GLOBALS['xoops']->path('modules/' . $module->getVar('dirname', 'n') . '/templates/blocks/'); |
||
73 | if (is_dir($templateDirectory)) { |
||
74 | $templateList = array_diff(scandir($templateDirectory, SCANDIR_SORT_NONE), ['..', '.']); |
||
75 | foreach ($templateList as $k => $v) { |
||
76 | $fileInfo = new \SplFileInfo($templateDirectory . $v); |
||
77 | if ('html' === $fileInfo->getExtension() && 'index.html' !== $fileInfo->getFilename()) { |
||
78 | if (is_file($templateDirectory . $v)) { |
||
79 | unlink($templateDirectory . $v); |
||
80 | } |
||
81 | } |
||
82 | } |
||
83 | } |
||
84 | //delete old files: =================== |
||
85 | $oldFiles = [ |
||
86 | '/assets/images/logo_module.png', |
||
87 | '/templates/gbook.css', |
||
88 | ]; |
||
89 | |||
90 | foreach (array_keys($oldFiles) as $file) { |
||
91 | if (is_file($file)) { |
||
92 | unlink($GLOBALS['xoops']->path('modules/' . $module->getVar('dirname', 'n') . $oldFiles[$file])); |
||
93 | } |
||
94 | } |
||
95 | |||
96 | //delete .html entries from the tpl table |
||
97 | $sql = 'DELETE FROM ' . $xoopsDB->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.html%'"; |
||
98 | $xoopsDB->queryF($sql); |
||
99 | |||
100 | // Load class XoopsFile ==================== |
||
101 | xoops_load('XoopsFile'); |
||
102 | |||
103 | //delete /images directory ============ |
||
104 | $imagesDirectory = $GLOBALS['xoops']->path('modules/' . $module->getVar('dirname', 'n') . '/images/'); |
||
105 | $folderHandler = XoopsFile::getHandler('folder', $imagesDirectory); |
||
106 | $folderHandler->delete($imagesDirectory); |
||
107 | } |
||
108 | |||
109 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||
110 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
111 | |||
112 | return $grouppermHandler->deleteByModule($module->getVar('mid'), 'item_read'); |
||
113 | } |
||
114 |