| Conditions | 20 |
| Paths | 254 |
| Total Lines | 189 |
| Code Lines | 86 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 1 | 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); |
||
| 58 | function xoops_module_install_tdmdownloads() |
||
| 59 | { |
||
| 60 | global $xoopsModule, $xoopsConfig, $xoopsDB; |
||
| 61 | |||
| 62 | $moduleDirName = basename(dirname(__DIR__)); |
||
| 63 | |||
| 64 | $namemodule = $moduleDirName; |
||
| 65 | |||
| 66 | if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/language/' . $xoopsConfig['language'] . '/admin.php')) { |
||
| 67 | require_once XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/language/' . $xoopsConfig['language'] . '/admin.php'; |
||
| 68 | } else { |
||
| 69 | require_once XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/language/english/admin.php'; |
||
| 70 | } |
||
| 71 | |||
| 72 | $fieldHandler = Helper::getInstance()->getHandler('Field'); |
||
| 73 | |||
| 74 | $obj = $fieldHandler->create(); |
||
| 75 | |||
| 76 | $obj->setVar('title', _AM_TDMDOWNLOADS_FORMHOMEPAGE); |
||
| 77 | |||
| 78 | $obj->setVar('img', 'homepage.png'); |
||
| 79 | |||
| 80 | $obj->setVar('weight', 1); |
||
| 81 | |||
| 82 | $obj->setVar('search', 0); |
||
| 83 | |||
| 84 | $obj->setVar('status', 1); |
||
| 85 | |||
| 86 | $obj->setVar('status_def', 1); |
||
| 87 | |||
| 88 | $fieldHandler->insert($obj); |
||
| 89 | |||
| 90 | $obj = $fieldHandler->create(); |
||
| 91 | |||
| 92 | $obj->setVar('title', _AM_TDMDOWNLOADS_FORMVERSION); |
||
| 93 | |||
| 94 | $obj->setVar('img', 'version.png'); |
||
| 95 | |||
| 96 | $obj->setVar('weight', 2); |
||
| 97 | |||
| 98 | $obj->setVar('search', 0); |
||
| 99 | |||
| 100 | $obj->setVar('status', 1); |
||
| 101 | |||
| 102 | $obj->setVar('status_def', 1); |
||
| 103 | |||
| 104 | $fieldHandler->insert($obj); |
||
| 105 | |||
| 106 | $obj = $fieldHandler->create(); |
||
| 107 | |||
| 108 | $obj->setVar('title', _AM_TDMDOWNLOADS_FORMSIZE); |
||
| 109 | |||
| 110 | $obj->setVar('img', 'size.png'); |
||
| 111 | |||
| 112 | $obj->setVar('weight', 3); |
||
| 113 | |||
| 114 | $obj->setVar('search', 0); |
||
| 115 | |||
| 116 | $obj->setVar('status', 1); |
||
| 117 | |||
| 118 | $obj->setVar('status_def', 1); |
||
| 119 | |||
| 120 | $fieldHandler->insert($obj); |
||
| 121 | |||
| 122 | $obj = $fieldHandler->create(); |
||
| 123 | |||
| 124 | $obj->setVar('title', _AM_TDMDOWNLOADS_FORMPLATFORM); |
||
| 125 | |||
| 126 | $obj->setVar('img', 'platform.png'); |
||
| 127 | |||
| 128 | $obj->setVar('weight', 4); |
||
| 129 | |||
| 130 | $obj->setVar('search', 0); |
||
| 131 | |||
| 132 | $obj->setVar('status', 1); |
||
| 133 | |||
| 134 | $obj->setVar('status_def', 1); |
||
| 135 | |||
| 136 | $fieldHandler->insert($obj); |
||
| 137 | |||
| 138 | //File creation ".$namemodule."/ |
||
| 139 | |||
| 140 | $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . ''; |
||
| 141 | |||
| 142 | if (!is_dir($dir)) { |
||
| 143 | if (!mkdir($dir, 0777) && !is_dir($dir)) { |
||
| 144 | throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); |
||
| 145 | } |
||
| 146 | } |
||
| 147 | |||
| 148 | chmod($dir, 0777); |
||
| 149 | |||
| 150 | //File creation ".$namemodule."/images/ |
||
| 151 | |||
| 152 | $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images'; |
||
| 153 | |||
| 154 | if (!is_dir($dir)) { |
||
| 155 | if (!mkdir($dir, 0777) && !is_dir($dir)) { |
||
| 156 | throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); |
||
| 157 | } |
||
| 158 | } |
||
| 159 | |||
| 160 | chmod($dir, 0777); |
||
| 161 | |||
| 162 | //File creation ".$namemodule."/images/cat |
||
| 163 | |||
| 164 | $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/cats'; |
||
| 165 | |||
| 166 | if (!is_dir($dir)) { |
||
| 167 | if (!mkdir($dir, 0777) && !is_dir($dir)) { |
||
| 168 | throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); |
||
| 169 | } |
||
| 170 | } |
||
| 171 | |||
| 172 | chmod($dir, 0777); |
||
| 173 | |||
| 174 | //File creation ".$namemodule."/images/shots |
||
| 175 | |||
| 176 | $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/shots'; |
||
| 177 | |||
| 178 | if (!is_dir($dir)) { |
||
| 179 | if (!mkdir($dir, 0777) && !is_dir($dir)) { |
||
| 180 | throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); |
||
| 181 | } |
||
| 182 | } |
||
| 183 | |||
| 184 | chmod($dir, 0777); |
||
| 185 | |||
| 186 | //File creation ".$namemodule."/images/field |
||
| 187 | |||
| 188 | $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field'; |
||
| 189 | |||
| 190 | if (!is_dir($dir)) { |
||
| 191 | if (!mkdir($dir, 0777) && !is_dir($dir)) { |
||
| 192 | throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); |
||
| 193 | } |
||
| 194 | } |
||
| 195 | |||
| 196 | chmod($dir, 0777); |
||
| 197 | |||
| 198 | //File creation ".$namemodule."/downloads |
||
| 199 | |||
| 200 | $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/downloads'; |
||
| 201 | |||
| 202 | if (!is_dir($dir)) { |
||
| 203 | if (!mkdir($dir, 0777) && !is_dir($dir)) { |
||
| 204 | throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); |
||
| 205 | } |
||
| 206 | } |
||
| 207 | |||
| 208 | chmod($dir, 0777); |
||
| 209 | |||
| 210 | //Copy index.html |
||
| 211 | |||
| 212 | $indexFile = XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/include/index.html'; |
||
| 213 | |||
| 214 | copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/index.html'); |
||
| 215 | |||
| 216 | copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/index.html'); |
||
| 217 | |||
| 218 | copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/cats/index.html'); |
||
| 219 | |||
| 220 | copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/shots/index.html'); |
||
| 221 | |||
| 222 | copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/index.html'); |
||
| 223 | |||
| 224 | copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/downloads/index.html'); |
||
| 225 | |||
| 226 | //Copy blank.gif |
||
| 227 | |||
| 228 | $blankFile = XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/assets/images/blank.gif'; |
||
| 229 | |||
| 230 | copy($blankFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/cats/blank.gif'); |
||
| 231 | |||
| 232 | copy($blankFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/shots/blank.gif'); |
||
| 233 | |||
| 234 | copy($blankFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/blank.gif'); |
||
| 235 | |||
| 236 | //Copy images for fields |
||
| 237 | |||
| 238 | copy(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/assets/images/icons/16/homepage.png', XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/homepage.png'); |
||
| 239 | |||
| 240 | copy(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/assets/images/icons/16/version.png', XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/version.png'); |
||
| 241 | |||
| 242 | copy(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/assets/images/icons/16/size.png', XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/size.png'); |
||
| 243 | |||
| 244 | copy(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/assets/images/icons/16/platform.png', XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/platform.png'); |
||
| 245 | |||
| 246 | return true; |
||
| 247 | } |
||
| 248 |