Conditions | 20 |
Paths | 254 |
Total Lines | 110 |
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 |
||
49 | function xoops_module_install_tdmdownloads() |
||
50 | { |
||
51 | global $xoopsModule, $xoopsConfig, $xoopsDB; |
||
52 | $moduleDirName = basename(dirname(__DIR__)); |
||
53 | $namemodule = $moduleDirName; |
||
54 | if (is_file(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/language/' . $xoopsConfig['language'] . '/admin.php')) { |
||
55 | require_once XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/language/' . $xoopsConfig['language'] . '/admin.php'; |
||
56 | } else { |
||
57 | require_once XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/language/english/admin.php'; |
||
58 | } |
||
59 | $fieldHandler = Helper::getInstance()->getHandler('Field'); |
||
60 | $obj = $fieldHandler->create(); |
||
61 | $obj->setVar('title', _AM_TDMDOWNLOADS_FORMHOMEPAGE); |
||
62 | $obj->setVar('img', 'homepage.png'); |
||
63 | $obj->setVar('weight', 1); |
||
64 | $obj->setVar('search', 0); |
||
65 | $obj->setVar('status', 1); |
||
66 | $obj->setVar('status_def', 1); |
||
67 | $fieldHandler->insert($obj); |
||
68 | $obj = $fieldHandler->create(); |
||
69 | $obj->setVar('title', _AM_TDMDOWNLOADS_FORMVERSION); |
||
70 | $obj->setVar('img', 'version.png'); |
||
71 | $obj->setVar('weight', 2); |
||
72 | $obj->setVar('search', 0); |
||
73 | $obj->setVar('status', 1); |
||
74 | $obj->setVar('status_def', 1); |
||
75 | $fieldHandler->insert($obj); |
||
76 | $obj = $fieldHandler->create(); |
||
77 | $obj->setVar('title', _AM_TDMDOWNLOADS_FORMSIZE); |
||
78 | $obj->setVar('img', 'size.png'); |
||
79 | $obj->setVar('weight', 3); |
||
80 | $obj->setVar('search', 0); |
||
81 | $obj->setVar('status', 1); |
||
82 | $obj->setVar('status_def', 1); |
||
83 | $fieldHandler->insert($obj); |
||
84 | $obj = $fieldHandler->create(); |
||
85 | $obj->setVar('title', _AM_TDMDOWNLOADS_FORMPLATFORM); |
||
86 | $obj->setVar('img', 'platform.png'); |
||
87 | $obj->setVar('weight', 4); |
||
88 | $obj->setVar('search', 0); |
||
89 | $obj->setVar('status', 1); |
||
90 | $obj->setVar('status_def', 1); |
||
91 | $fieldHandler->insert($obj); |
||
92 | //File creation ".$namemodule."/ |
||
93 | $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . ''; |
||
94 | if (!is_dir($dir)) { |
||
95 | if (!mkdir($dir, 0777) && !is_dir($dir)) { |
||
96 | throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); |
||
97 | } |
||
98 | } |
||
99 | chmod($dir, 0777); |
||
100 | //File creation ".$namemodule."/images/ |
||
101 | $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images'; |
||
102 | if (!is_dir($dir)) { |
||
103 | if (!mkdir($dir, 0777) && !is_dir($dir)) { |
||
104 | throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); |
||
105 | } |
||
106 | } |
||
107 | chmod($dir, 0777); |
||
108 | //File creation ".$namemodule."/images/cat |
||
109 | $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/cats'; |
||
110 | if (!is_dir($dir)) { |
||
111 | if (!mkdir($dir, 0777) && !is_dir($dir)) { |
||
112 | throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); |
||
113 | } |
||
114 | } |
||
115 | chmod($dir, 0777); |
||
116 | //File creation ".$namemodule."/images/shots |
||
117 | $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/shots'; |
||
118 | if (!is_dir($dir)) { |
||
119 | if (!mkdir($dir, 0777) && !is_dir($dir)) { |
||
120 | throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); |
||
121 | } |
||
122 | } |
||
123 | chmod($dir, 0777); |
||
124 | //File creation ".$namemodule."/images/field |
||
125 | $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field'; |
||
126 | if (!is_dir($dir)) { |
||
127 | if (!mkdir($dir, 0777) && !is_dir($dir)) { |
||
128 | throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); |
||
129 | } |
||
130 | } |
||
131 | chmod($dir, 0777); |
||
132 | //File creation ".$namemodule."/downloads |
||
133 | $dir = XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/downloads'; |
||
134 | if (!is_dir($dir)) { |
||
135 | if (!mkdir($dir, 0777) && !is_dir($dir)) { |
||
136 | throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); |
||
137 | } |
||
138 | } |
||
139 | chmod($dir, 0777); |
||
140 | //Copy index.html |
||
141 | $indexFile = XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/include/index.php'; |
||
142 | copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/index.php'); |
||
143 | copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/index.php'); |
||
144 | copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/cats/index.php'); |
||
145 | copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/shots/index.php'); |
||
146 | copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/index.php'); |
||
147 | copy($indexFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/downloads/index.php'); |
||
148 | //Copy blank.gif |
||
149 | $blankFile = XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/assets/images/blank.gif'; |
||
150 | copy($blankFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/cats/blank.gif'); |
||
151 | copy($blankFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/shots/blank.gif'); |
||
152 | copy($blankFile, XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/blank.gif'); |
||
153 | //Copy images for fields |
||
154 | copy(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/assets/images/icons/16/homepage.png', XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/homepage.png'); |
||
155 | copy(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/assets/images/icons/16/version.png', XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/version.png'); |
||
156 | copy(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/assets/images/icons/16/size.png', XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/size.png'); |
||
157 | copy(XOOPS_ROOT_PATH . '/modules/' . $namemodule . '/assets/images/icons/16/platform.png', XOOPS_ROOT_PATH . '/uploads/' . $namemodule . '/images/field/platform.png'); |
||
158 | return true; |
||
159 | } |
||
160 |