Conditions | 13 |
Paths | 4 |
Total Lines | 89 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
54 | function xoops_module_update_xsitemap(\XoopsModule $module, $previousVersion = null) |
||
55 | { |
||
56 | /*====================================================================== |
||
57 | //---------------------------------------------------------------- |
||
58 | // Remove xSitemap uploads folder (and all subfolders) if they exist |
||
59 | //----------------------------------------------------------------* |
||
60 | $utility = new Xsitemap\Utility(); |
||
61 | if (!class_exists($utility)) { |
||
62 | xoops_load('utility', $moduleDirName); |
||
63 | } |
||
64 | |||
65 | // Recursively delete directories |
||
66 | $xsUploadDir = realpath(XOOPS_UPLOAD_PATH . "/" . $module->dirname()); |
||
67 | $success = $utility::rrmdir($xsUploadDir); |
||
68 | if (true !== $success) { |
||
69 | \Xmf\Language::load('admin', $module->dirname()); |
||
70 | $module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_DEL_PATH, $xsUploadDir)); |
||
71 | } |
||
72 | return $success; |
||
73 | ======================================================================*/ |
||
74 | $moduleDirName = basename(dirname(__DIR__)); |
||
75 | $moduleDirNameUpper = mb_strtoupper($moduleDirName); |
||
76 | /** @var Xsitemap\Helper $helper */ /** @var Xsitemap\Utility $utility */ |
||
77 | /** @var Xsitemap\Common\Configurator $configurator */ |
||
78 | $helper = Xsitemap\Helper::getInstance(); |
||
79 | $utility = new Xsitemap\Utility(); |
||
80 | $configurator = new Xsitemap\Common\Configurator(); |
||
81 | //----------------------------------------------------------------------- |
||
82 | // Upgrade for Xsitemap < 1.54 |
||
83 | //----------------------------------------------------------------------- |
||
84 | $success = true; |
||
85 | $helper->loadLanguage('modinfo'); |
||
86 | $helper->loadLanguage('admin'); |
||
87 | if ($previousVersion < 154) { |
||
88 | //---------------------------------------------------------------- |
||
89 | // Remove previous css & images directories since they've been relocated to ./assets |
||
90 | // Also remove uploads directories since they're no longer used |
||
91 | //---------------------------------------------------------------- |
||
92 | $old_directories = [ |
||
93 | $helper->path('css/'), |
||
94 | $helper->path('js/'), |
||
95 | $helper->path('images/'), |
||
96 | XOOPS_UPLOAD_PATH . '/' . $module->dirname(), |
||
97 | ]; |
||
98 | foreach ($old_directories as $old_dir) { |
||
99 | $dirInfo = new \SplFileInfo($old_dir); |
||
100 | if ($dirInfo->isDir()) { |
||
101 | // The directory exists so delete it |
||
102 | if (false === $utility::rrmdir($old_dir)) { |
||
103 | $module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_DEL_PATH, $old_dir)); |
||
104 | return false; |
||
105 | } |
||
106 | } |
||
107 | unset($dirInfo); |
||
108 | } |
||
109 | //----------------------------------------------------------------------- |
||
110 | // Remove ./template/*.html (except index.html) files since they've |
||
111 | // been replaced by *.tpl files |
||
112 | // Note: this will also remove /template/xsitemap_style.html since it's no longer used |
||
113 | //----------------------------------------------------------------------- |
||
114 | $path = $helper->path('templates/'); |
||
115 | $unfiltered = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); |
||
116 | $iterator = new RegexIterator($unfiltered, "/.*\.html/"); |
||
117 | foreach ($iterator as $name => $fObj) { |
||
118 | if ($fObj->isFile() && ('index.html' !== $fObj->getFilename())) { |
||
119 | if (false === ($success = unlink($fObj->getPathname()))) { |
||
120 | $module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_REMOVE, $fObj->getPathname())); |
||
121 | return false; |
||
122 | } |
||
123 | } |
||
124 | } |
||
125 | //----------------------------------------------------------------------- |
||
126 | // Now remove a some misc files that were renamed or deprecated |
||
127 | //----------------------------------------------------------------------- |
||
128 | $oldFiles = [ |
||
129 | $helper->path('include/install.php'), |
||
130 | $helper->path('class/module.php'), |
||
131 | $helper->path('class/menu.php'), |
||
132 | ]; |
||
133 | foreach ($oldFiles as $file) { |
||
134 | if (is_file($file)) { |
||
135 | if (false === ($delOk = unlink($file))) { |
||
136 | $module->setErrors(sprintf(_AM_XSITEMAP_ERROR_BAD_REMOVE, $file)); |
||
137 | } |
||
138 | $success = $success && $delOk; |
||
139 | } |
||
140 | } |
||
141 | } |
||
142 | return $success; |
||
143 | } |
||
144 |