Conditions | 13 |
Paths | 4 |
Total Lines | 96 |
Code Lines | 38 |
Lines | 57 |
Ratio | 59.38 % |
Changes | 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 |
||
116 | $success = $utility::rrmdir($xsUploadDir); |
||
117 | if (true !== $success) { |
||
118 | \Xmf\Language::load('admin', $module->dirname()); |
||
119 | $module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_DEL_PATH, $xsUploadDir)); |
||
120 | } |
||
121 | return $success; |
||
122 | ======================================================================*/ |
||
123 | $moduleDirName = basename(dirname(__DIR__)); |
||
124 | $moduleDirNameUpper = mb_strtoupper($moduleDirName); |
||
125 | /** @var Xsitemap\Helper $helper */ /** @var Xsitemap\Utility $utility */ |
||
126 | /** @var Xsitemap\Common\Configurator $configurator */ |
||
127 | $helper = Helper::getInstance(); |
||
128 | $utility = new Xsitemap\Utility(); |
||
129 | $configurator = new Xsitemap\Common\Configurator(); |
||
130 | //----------------------------------------------------------------------- |
||
131 | // Upgrade for Xsitemap < 1.54 |
||
132 | //----------------------------------------------------------------------- |
||
133 | $success = true; |
||
134 | $helper->loadLanguage('modinfo'); |
||
135 | $helper->loadLanguage('admin'); |
||
136 | if ($previousVersion < 154) { |
||
137 | //---------------------------------------------------------------- |
||
138 | // Remove previous css & images directories since they've been relocated to ./assets |
||
139 | // Also remove uploads directories since they're no longer used |
||
140 | //---------------------------------------------------------------- |
||
141 | $old_directories = [ |
||
142 | $helper->path('css/'), |
||
143 | $helper->path('js/'), |
||
144 | $helper->path('images/'), |
||
145 | XOOPS_UPLOAD_PATH . '/' . $module->dirname(), |
||
146 | ]; |
||
147 | foreach ($old_directories as $old_dir) { |
||
148 | $dirInfo = new \SplFileInfo($old_dir); |
||
149 | if ($dirInfo->isDir()) { |
||
150 | // The directory exists so delete it |
||
151 | if (false === $utility::rrmdir($old_dir)) { |
||
152 | $module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_DEL_PATH, $old_dir)); |
||
153 | return false; |
||
154 | } |
||
155 | } |
||
156 | unset($dirInfo); |
||
157 | } |
||
158 | //----------------------------------------------------------------------- |
||
159 | // Remove ./template/*.html (except index.html) files since they've |
||
160 | // been replaced by *.tpl files |
||
161 | // Note: this will also remove /template/xsitemap_style.html since it's no longer used |
||
162 | //----------------------------------------------------------------------- |
||
163 | $path = $helper->path('templates/'); |
||
164 | $unfiltered = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); |
||
165 | $iterator = new RegexIterator($unfiltered, "/.*\.html/"); |
||
166 | foreach ($iterator as $name => $fObj) { |
||
167 | if ($fObj->isFile() && ('index.html' !== $fObj->getFilename())) { |
||
168 | if (false === ($success = unlink($fObj->getPathname()))) { |
||
169 | $module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_REMOVE, $fObj->getPathname())); |
||
170 | return false; |
||
171 | } |
||
172 | } |
||
173 | } |
||
174 | //----------------------------------------------------------------------- |
||
175 | // Now remove a some misc files that were renamed or deprecated |
||
176 | //----------------------------------------------------------------------- |
||
177 | $oldFiles = [ |
||
178 | $helper->path('include/install.php'), |
||
179 | $helper->path('class/module.php'), |
||
180 | $helper->path('class/menu.php'), |
||
181 | ]; |
||
182 | foreach ($oldFiles as $file) { |
||
183 | if (is_file($file)) { |
||
184 | if (false === ($delOk = unlink($file))) { |
||
185 | $module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_REMOVE, $file)); |
||
186 | } |
||
187 | $success = $success && $delOk; |
||
188 | } |
||
189 | } |
||
190 | } |
||
191 | return $success; |
||
192 | } |
||
193 | |||
194 | /** |
||
195 | * Function to perform before module uninstall |
||
196 | * |
||
197 | * @param \XoopsModule $module |
||
198 | * |
||
199 | * @return bool true if successfully executed, false if not |
||
200 | */ |
||
201 | function xoops_module_pre_uninstall_xsitemap(\XoopsModule $module) |
||
202 | { |
||
203 | return true; |
||
204 | } |
||
205 | |||
206 | /** |
||
207 | * Function to complete upon module uninstall |
||
208 | * |
||
209 | * @param \XoopsModule $module |
||
210 | * |
||
211 | * @return bool true if successfully executed uninstall of module, false if not |
||
212 | */ |
||
251 |