Conditions | 8 |
Paths | 128 |
Total Lines | 102 |
Code Lines | 80 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
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 |
||
17 | function xoops_module_install_tdmdownloads() { |
||
18 | global $xoopsModule, $xoopsConfig, $xoopsDB; |
||
|
|||
19 | |||
20 | $namemodule = "TDMDownloads"; |
||
21 | if( file_exists(XOOPS_ROOT_PATH."/modules/".$namemodule."/language/".$xoopsConfig['language']."/admin.php") ) { |
||
22 | include_once(XOOPS_ROOT_PATH."/modules/".$namemodule."/language/".$xoopsConfig['language']."/admin.php"); |
||
23 | } else { |
||
24 | include_once(XOOPS_ROOT_PATH."/modules/".$namemodule."/language/english/admin.php"); |
||
25 | } |
||
26 | $downloadsfield_Handler =& xoops_getModuleHandler('tdmdownloads_field', 'TDMDownloads'); |
||
27 | $obj =& $downloadsfield_Handler->create(); |
||
28 | $obj->setVar('title', _AM_TDMDOWNLOADS_FORMHOMEPAGE); |
||
29 | $obj->setVar('img', 'homepage.png'); |
||
30 | $obj->setVar('weight', 1); |
||
31 | $obj->setVar('search', 0); |
||
32 | $obj->setVar('status', 1); |
||
33 | $obj->setVar('status_def', 1); |
||
34 | $downloadsfield_Handler->insert($obj); |
||
35 | $obj =& $downloadsfield_Handler->create(); |
||
36 | $obj->setVar('title', _AM_TDMDOWNLOADS_FORMVERSION); |
||
37 | $obj->setVar('img', 'version.png'); |
||
38 | $obj->setVar('weight', 2); |
||
39 | $obj->setVar('search', 0); |
||
40 | $obj->setVar('status', 1); |
||
41 | $obj->setVar('status_def', 1); |
||
42 | $downloadsfield_Handler->insert($obj); |
||
43 | $obj =& $downloadsfield_Handler->create(); |
||
44 | $obj->setVar('title', _AM_TDMDOWNLOADS_FORMSIZE); |
||
45 | $obj->setVar('img', 'size.png'); |
||
46 | $obj->setVar('weight', 3); |
||
47 | $obj->setVar('search', 0); |
||
48 | $obj->setVar('status', 1); |
||
49 | $obj->setVar('status_def', 1); |
||
50 | $downloadsfield_Handler->insert($obj); |
||
51 | $obj =& $downloadsfield_Handler->create(); |
||
52 | $obj->setVar('title', _AM_TDMDOWNLOADS_FORMPLATFORM); |
||
53 | $obj->setVar('img', 'platform.png'); |
||
54 | $obj->setVar('weight', 4); |
||
55 | $obj->setVar('search', 0); |
||
56 | $obj->setVar('status', 1); |
||
57 | $obj->setVar('status_def', 1); |
||
58 | $downloadsfield_Handler->insert($obj); |
||
59 | |||
60 | //Creation du fichier ".$namemodule."/ |
||
61 | $dir = XOOPS_ROOT_PATH."/uploads/".$namemodule.""; |
||
62 | if(!is_dir($dir)) |
||
63 | mkdir($dir, 0777); |
||
64 | chmod($dir, 0777); |
||
65 | |||
66 | //Creation du fichier ".$namemodule."/images/ |
||
67 | $dir = XOOPS_ROOT_PATH."/uploads/".$namemodule."/images"; |
||
68 | if(!is_dir($dir)) |
||
69 | mkdir($dir, 0777); |
||
70 | chmod($dir, 0777); |
||
71 | |||
72 | //Creation du fichier ".$namemodule."/images/cat |
||
73 | $dir = XOOPS_ROOT_PATH."/uploads/".$namemodule."/images/cats"; |
||
74 | if(!is_dir($dir)) |
||
75 | mkdir($dir, 0777); |
||
76 | chmod($dir, 0777); |
||
77 | |||
78 | //Creation du fichier ".$namemodule."/images/shots |
||
79 | $dir = XOOPS_ROOT_PATH."/uploads/".$namemodule."/images/shots"; |
||
80 | if(!is_dir($dir)) |
||
81 | mkdir($dir, 0777); |
||
82 | chmod($dir, 0777); |
||
83 | |||
84 | //Creation du fichier ".$namemodule."/images/field |
||
85 | $dir = XOOPS_ROOT_PATH."/uploads/".$namemodule."/images/field"; |
||
86 | if(!is_dir($dir)) |
||
87 | mkdir($dir, 0777); |
||
88 | chmod($dir, 0777); |
||
89 | |||
90 | //Creation du fichier ".$namemodule."/downloads |
||
91 | $dir = XOOPS_ROOT_PATH."/uploads/".$namemodule."/downloads"; |
||
92 | if(!is_dir($dir)) |
||
93 | mkdir($dir, 0777); |
||
94 | chmod($dir, 0777); |
||
95 | |||
96 | //Copie des index.html |
||
97 | $indexFile = XOOPS_ROOT_PATH."/modules/".$namemodule."/include/index.html"; |
||
98 | copy($indexFile, XOOPS_ROOT_PATH."/uploads/".$namemodule."/index.html"); |
||
99 | copy($indexFile, XOOPS_ROOT_PATH."/uploads/".$namemodule."/images/index.html"); |
||
100 | copy($indexFile, XOOPS_ROOT_PATH."/uploads/".$namemodule."/images/cats/index.html"); |
||
101 | copy($indexFile, XOOPS_ROOT_PATH."/uploads/".$namemodule."/images/shots/index.html"); |
||
102 | copy($indexFile, XOOPS_ROOT_PATH."/uploads/".$namemodule."/images/field/index.html"); |
||
103 | copy($indexFile, XOOPS_ROOT_PATH."/uploads/".$namemodule."/downloads/index.html"); |
||
104 | |||
105 | //Copie des blank.gif |
||
106 | $blankFile = XOOPS_ROOT_PATH."/modules/".$namemodule."/images/blank.gif"; |
||
107 | copy($blankFile, XOOPS_ROOT_PATH."/uploads/".$namemodule."/images/cats/blank.gif"); |
||
108 | copy($blankFile, XOOPS_ROOT_PATH."/uploads/".$namemodule."/images/shots/blank.gif"); |
||
109 | copy($blankFile, XOOPS_ROOT_PATH."/uploads/".$namemodule."/images/field/blank.gif"); |
||
110 | |||
111 | //Copie des images pour les champs |
||
112 | copy(XOOPS_ROOT_PATH."/modules/".$namemodule."/images/icon/homepage.png", XOOPS_ROOT_PATH."/uploads/".$namemodule."/images/field/homepage.png"); |
||
113 | copy(XOOPS_ROOT_PATH."/modules/".$namemodule."/images/icon/version.png", XOOPS_ROOT_PATH."/uploads/".$namemodule."/images/field/version.png"); |
||
114 | copy(XOOPS_ROOT_PATH."/modules/".$namemodule."/images/icon/size.png", XOOPS_ROOT_PATH."/uploads/".$namemodule."/images/field/size.png"); |
||
115 | copy(XOOPS_ROOT_PATH."/modules/".$namemodule."/images/icon/platform.png", XOOPS_ROOT_PATH."/uploads/".$namemodule."/images/field/platform.png"); |
||
116 | |||
117 | return true; |
||
118 | } |
||
119 |
Instead of relying on
global
state, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state