| Conditions | 20 |
| Paths | 254 |
| Total Lines | 121 |
| Code Lines | 86 |
| 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 |
||
| 24 | function xoops_module_install_tdmdownloads() |
||
| 25 | { |
||
| 26 | global $xoopsModule, $xoopsConfig, $xoopsDB; |
||
| 27 | $moduleDirName = basename(dirname(__DIR__)); |
||
| 28 | |||
| 29 | $namemodule = $moduleDirName; |
||
| 30 | if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/language/' . $xoopsConfig['language'] . '/admin.php')) { |
||
| 31 | include_once XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/language/' . $xoopsConfig['language'] . '/admin.php'; |
||
| 32 | } else { |
||
| 33 | include_once XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/language/english/admin.php'; |
||
| 34 | } |
||
| 35 | $fieldHandler = \XoopsModules\Tdmdownloads\Helper::getInstance()->getHandler('Field'); |
||
| 36 | $obj = $fieldHandler->create(); |
||
| 37 | $obj->setVar('title', _AM_TDMDOWNLOADS_FORMHOMEPAGE); |
||
| 38 | $obj->setVar('img', 'homepage.png'); |
||
| 39 | $obj->setVar('weight', 1); |
||
| 40 | $obj->setVar('search', 0); |
||
| 41 | $obj->setVar('status', 1); |
||
| 42 | $obj->setVar('status_def', 1); |
||
| 43 | $fieldHandler->insert($obj); |
||
| 44 | $obj = $fieldHandler->create(); |
||
| 45 | $obj->setVar('title', _AM_TDMDOWNLOADS_FORMVERSION); |
||
| 46 | $obj->setVar('img', 'version.png'); |
||
| 47 | $obj->setVar('weight', 2); |
||
| 48 | $obj->setVar('search', 0); |
||
| 49 | $obj->setVar('status', 1); |
||
| 50 | $obj->setVar('status_def', 1); |
||
| 51 | $fieldHandler->insert($obj); |
||
| 52 | $obj = $fieldHandler->create(); |
||
| 53 | $obj->setVar('title', _AM_TDMDOWNLOADS_FORMSIZE); |
||
| 54 | $obj->setVar('img', 'size.png'); |
||
| 55 | $obj->setVar('weight', 3); |
||
| 56 | $obj->setVar('search', 0); |
||
| 57 | $obj->setVar('status', 1); |
||
| 58 | $obj->setVar('status_def', 1); |
||
| 59 | $fieldHandler->insert($obj); |
||
| 60 | $obj = $fieldHandler->create(); |
||
| 61 | $obj->setVar('title', _AM_TDMDOWNLOADS_FORMPLATFORM); |
||
| 62 | $obj->setVar('img', 'platform.png'); |
||
| 63 | $obj->setVar('weight', 4); |
||
| 64 | $obj->setVar('search', 0); |
||
| 65 | $obj->setVar('status', 1); |
||
| 66 | $obj->setVar('status_def', 1); |
||
| 67 | $fieldHandler->insert($obj); |
||
| 68 | |||
| 69 | //Creation du fichier ".$namemodule."/ |
||
| 70 | $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . ''; |
||
| 71 | if (!is_dir($dir)) { |
||
| 72 | if (!mkdir($dir, 0777) && !is_dir($dir)) { |
||
| 73 | throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); |
||
| 74 | } |
||
| 75 | } |
||
| 76 | chmod($dir, 0777); |
||
| 77 | |||
| 78 | //Creation du fichier ".$namemodule."/images/ |
||
| 79 | $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images'; |
||
| 80 | if (!is_dir($dir)) { |
||
| 81 | if (!mkdir($dir, 0777) && !is_dir($dir)) { |
||
| 82 | throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); |
||
| 83 | } |
||
| 84 | } |
||
| 85 | chmod($dir, 0777); |
||
| 86 | |||
| 87 | //Creation du fichier ".$namemodule."/images/cat |
||
| 88 | $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/cats'; |
||
| 89 | if (!is_dir($dir)) { |
||
| 90 | if (!mkdir($dir, 0777) && !is_dir($dir)) { |
||
| 91 | throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); |
||
| 92 | } |
||
| 93 | } |
||
| 94 | chmod($dir, 0777); |
||
| 95 | |||
| 96 | //Creation du fichier ".$namemodule."/images/shots |
||
| 97 | $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/shots'; |
||
| 98 | if (!is_dir($dir)) { |
||
| 99 | if (!mkdir($dir, 0777) && !is_dir($dir)) { |
||
| 100 | throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); |
||
| 101 | } |
||
| 102 | } |
||
| 103 | chmod($dir, 0777); |
||
| 104 | |||
| 105 | //Creation du fichier ".$namemodule."/images/field |
||
| 106 | $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field'; |
||
| 107 | if (!is_dir($dir)) { |
||
| 108 | if (!mkdir($dir, 0777) && !is_dir($dir)) { |
||
| 109 | throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); |
||
| 110 | } |
||
| 111 | } |
||
| 112 | chmod($dir, 0777); |
||
| 113 | |||
| 114 | //Creation du fichier ".$namemodule."/downloads |
||
| 115 | $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/downloads'; |
||
| 116 | if (!is_dir($dir)) { |
||
| 117 | if (!mkdir($dir, 0777) && !is_dir($dir)) { |
||
| 118 | throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); |
||
| 119 | } |
||
| 120 | } |
||
| 121 | chmod($dir, 0777); |
||
| 122 | |||
| 123 | //Copie des index.html |
||
| 124 | $indexFile = XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/include/index.html'; |
||
| 125 | copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/index.html'); |
||
| 126 | copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/index.html'); |
||
| 127 | copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/cats/index.html'); |
||
| 128 | copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/shots/index.html'); |
||
| 129 | copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/index.html'); |
||
| 130 | copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/downloads/index.html'); |
||
| 131 | |||
| 132 | //Copie des blank.gif |
||
| 133 | $blankFile = XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/images/blank.gif'; |
||
| 134 | copy($blankFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/cats/blank.gif'); |
||
| 135 | copy($blankFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/shots/blank.gif'); |
||
| 136 | copy($blankFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/blank.gif'); |
||
| 137 | |||
| 138 | //Copie des images pour les champs |
||
| 139 | copy(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/images/icon/homepage.png', XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/homepage.png'); |
||
| 140 | copy(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/images/icon/version.png', XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/version.png'); |
||
| 141 | copy(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/images/icon/size.png', XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/size.png'); |
||
| 142 | copy(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/images/icon/platform.png', XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/platform.png'); |
||
| 143 | |||
| 144 | return true; |
||
| 145 | } |
||
| 146 |