| Conditions | 14 |
| Paths | 8 |
| Total Lines | 71 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 65 | function xoops_module_update_xoopsfaq(XoopsModule $module, $prev_version) |
||
| 66 | { |
||
| 67 | $moduleDirName = $module->getVar('dirname'); |
||
| 68 | $helper = \XoopsModules\Xoopsfaq\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 (false === Xoopsfaq\Utility::rrmdir($old_dir)) { |
||
| 96 | $module->setErrors(sprintf(_AM_XOOPSFAQ_ERROR_BAD_DEL_PATH, $old_dir)); |
||
| 97 | return false; |
||
| 98 | } |
||
| 99 | } |
||
| 100 | unset($dirInfo); |
||
| 101 | } |
||
| 102 | |||
| 103 | //----------------------------------------------------------------------- |
||
| 104 | // Remove ./template/*.html (except index.html) files since they've |
||
| 105 | // been replaced by *.tpl files |
||
| 106 | //----------------------------------------------------------------------- |
||
| 107 | $path = $helper->path('templates/'); |
||
| 108 | $unfiltered = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); |
||
| 109 | $iterator = new RegexIterator($unfiltered, "/.*\.html/"); |
||
| 110 | foreach ($iterator as $name => $fObj) { |
||
| 111 | if (($fObj->isFile()) && ('index.html' !== $fObj->getFilename())) { |
||
| 112 | if (false === ($success = unlink($fObj->getPathname()))) { |
||
| 113 | $module->setErrors(sprintf(_AM_XOOPSFAQ_ERROR_BAD_REMOVE, $fObj->getPathname())); |
||
| 114 | return false; |
||
| 115 | } |
||
| 116 | } |
||
| 117 | } |
||
| 118 | |||
| 119 | //----------------------------------------------------------------------- |
||
| 120 | // Now remove a some misc files that were renamed or deprecated |
||
| 121 | //----------------------------------------------------------------------- |
||
| 122 | $oldFiles = [ |
||
| 123 | $helper->path('include/functions.php'), |
||
| 124 | $helper->path('class/utilities.php'), |
||
| 125 | ]; |
||
| 126 | foreach ($oldFiles as $file) { |
||
| 127 | if (is_file($file)) { |
||
| 128 | if (false === ($delOk = unlink($file))) { |
||
| 129 | $module->setErrors(sprintf(_AM_XOOPSFAQ_ERROR_BAD_REMOVE, $file)); |
||
| 130 | } |
||
| 131 | $success = $success && $delOk; |
||
| 132 | } |
||
| 133 | } |
||
| 134 | } |
||
| 135 | return $success; |
||
| 136 | } |
||
| 137 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.