Conditions | 13 |
Paths | 4 |
Total Lines | 74 |
Code Lines | 34 |
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); |
||
65 | function xoops_module_update_xoopsfaq(XoopsModule $module, string $prev_version) |
||
66 | { |
||
67 | $moduleDirName = $module->getVar('dirname'); |
||
68 | $helper = Helper::getInstance(); |
||
69 | // if (!class_exists('Xoopsfaq\Utility')) { |
||
70 | // xoops_load('utility', $moduleDirName); |
||
71 | // } |
||
72 | |||
73 | //---------------------------------------------------------------- |
||
74 | // Upgrade for Xoopsfaq < 1.25 |
||
75 | //---------------------------------------------------------------- |
||
76 | $success = true; |
||
77 | |||
78 | $helper->loadLanguage('modinfo'); |
||
79 | $helper->loadLanguage('admin'); |
||
80 | |||
81 | if ($prev_version < 125) { |
||
82 | //---------------------------------------------------------------- |
||
83 | // Remove previous .css, .js and .images directories since they've |
||
84 | // been relocated to ./assets |
||
85 | //---------------------------------------------------------------- |
||
86 | $old_directories = [ |
||
87 | $helper->path('css/'), |
||
88 | $helper->path('js/'), |
||
89 | $helper->path('images/'), |
||
90 | ]; |
||
91 | foreach ($old_directories as $old_dir) { |
||
92 | $dirInfo = new SplFileInfo($old_dir); |
||
93 | if ($dirInfo->isDir()) { |
||
94 | // The directory exists so delete it |
||
95 | if (!Utility::rrmdir($old_dir)) { |
||
96 | $module->setErrors(sprintf(_AM_XOOPSFAQ_ERROR_BAD_DEL_PATH, $old_dir)); |
||
97 | |||
98 | return false; |
||
99 | } |
||
100 | } |
||
101 | unset($dirInfo); |
||
102 | } |
||
103 | |||
104 | //----------------------------------------------------------------------- |
||
105 | // Remove ./template/*.html (except index.html) files since they've |
||
106 | // been replaced by *.tpl files |
||
107 | //----------------------------------------------------------------------- |
||
108 | $path = $helper->path('templates/'); |
||
109 | $unfiltered = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); |
||
110 | $iterator = new RegexIterator($unfiltered, '/.*\.html/'); |
||
111 | foreach ($iterator as $name => $fObj) { |
||
112 | if (($fObj->isFile()) && ('index.html' !== $fObj->getFilename())) { |
||
113 | if (false === ($success = unlink($fObj->getPathname()))) { |
||
114 | $module->setErrors(sprintf(_AM_XOOPSFAQ_ERROR_BAD_REMOVE, $fObj->getPathname())); |
||
115 | |||
116 | return false; |
||
117 | } |
||
118 | } |
||
119 | } |
||
120 | |||
121 | //----------------------------------------------------------------------- |
||
122 | // Now remove a some misc files that were renamed or deprecated |
||
123 | //----------------------------------------------------------------------- |
||
124 | $oldFiles = [ |
||
125 | $helper->path('include/functions.php'), |
||
126 | $helper->path('class/utilities.php'), |
||
127 | ]; |
||
128 | foreach ($oldFiles as $file) { |
||
129 | if (is_file($file)) { |
||
130 | if (false === ($delOk = unlink($file))) { |
||
131 | $module->setErrors(sprintf(_AM_XOOPSFAQ_ERROR_BAD_REMOVE, $file)); |
||
132 | } |
||
133 | $success = $success && $delOk; |
||
134 | } |
||
135 | } |
||
136 | } |
||
137 | |||
138 | return $success; |
||
139 | } |
||
140 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.