Conditions | 6 |
Paths | 8 |
Total Lines | 144 |
Code Lines | 40 |
Lines | 7 |
Ratio | 4.86 % |
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 |
||
58 | function xoops_module_install_extgallery(XoopsModule $xoopsModule) |
||
59 | { |
||
60 | $module_id = $xoopsModule->getVar('mid'); |
||
61 | /** @var XoopsGroupPermHandler $gpermHandler */ |
||
62 | $gpermHandler = xoops_getHandler('groupperm'); |
||
63 | /** @var XoopsModuleHandler $moduleHandler */ |
||
64 | $configHandler = xoops_getHandler('config'); |
||
65 | |||
66 | /** |
||
67 | * Default public category permission mask |
||
68 | */ |
||
69 | |||
70 | // Access right |
||
71 | $gpermHandler->addRight('extgallery_public_mask', 1, XOOPS_GROUP_ADMIN, $module_id); |
||
72 | $gpermHandler->addRight('extgallery_public_mask', 1, XOOPS_GROUP_USERS, $module_id); |
||
73 | $gpermHandler->addRight('extgallery_public_mask', 1, XOOPS_GROUP_ANONYMOUS, $module_id); |
||
74 | |||
75 | // Public rate |
||
76 | $gpermHandler->addRight('extgallery_public_mask', 2, XOOPS_GROUP_ADMIN, $module_id); |
||
77 | $gpermHandler->addRight('extgallery_public_mask', 2, XOOPS_GROUP_USERS, $module_id); |
||
78 | |||
79 | // Public eCard |
||
80 | $gpermHandler->addRight('extgallery_public_mask', 4, XOOPS_GROUP_ADMIN, $module_id); |
||
81 | $gpermHandler->addRight('extgallery_public_mask', 4, XOOPS_GROUP_USERS, $module_id); |
||
82 | |||
83 | // Public download |
||
84 | $gpermHandler->addRight('extgallery_public_mask', 8, XOOPS_GROUP_ADMIN, $module_id); |
||
85 | $gpermHandler->addRight('extgallery_public_mask', 8, XOOPS_GROUP_USERS, $module_id); |
||
86 | |||
87 | // Public upload |
||
88 | $gpermHandler->addRight('extgallery_public_mask', 16, XOOPS_GROUP_ADMIN, $module_id); |
||
89 | |||
90 | // Public autoapprove |
||
91 | $gpermHandler->addRight('extgallery_public_mask', 32, XOOPS_GROUP_ADMIN, $module_id); |
||
92 | |||
93 | // Public display |
||
94 | $gpermHandler->addRight('extgallery_public_mask', 128, XOOPS_GROUP_ADMIN, $module_id); |
||
95 | $gpermHandler->addRight('extgallery_public_mask', 128, XOOPS_GROUP_USERS, $module_id); |
||
96 | $gpermHandler->addRight('extgallery_public_mask', 128, XOOPS_GROUP_ANONYMOUS, $module_id); |
||
97 | |||
98 | /** |
||
99 | * Default User's category permission |
||
100 | */ |
||
101 | |||
102 | // Private gallery |
||
103 | |||
104 | // Private rate |
||
105 | $gpermHandler->addRight('extgallery_private', 2, XOOPS_GROUP_ADMIN, $module_id); |
||
106 | $gpermHandler->addRight('extgallery_private', 2, XOOPS_GROUP_USERS, $module_id); |
||
107 | |||
108 | // Private eCard |
||
109 | $gpermHandler->addRight('extgallery_private', 4, XOOPS_GROUP_ADMIN, $module_id); |
||
110 | $gpermHandler->addRight('extgallery_private', 4, XOOPS_GROUP_USERS, $module_id); |
||
111 | |||
112 | // Private download |
||
113 | $gpermHandler->addRight('extgallery_private', 8, XOOPS_GROUP_ADMIN, $module_id); |
||
114 | $gpermHandler->addRight('extgallery_private', 8, XOOPS_GROUP_USERS, $module_id); |
||
115 | |||
116 | // Private autoapprove |
||
117 | $gpermHandler->addRight('extgallery_private', 16, XOOPS_GROUP_ADMIN, $module_id); |
||
118 | |||
119 | /* |
||
120 | |||
121 | // Create eXtGallery main upload directory |
||
122 | $dir = XOOPS_ROOT_PATH . '/uploads/extgallery'; |
||
123 | if (!is_dir($dir)) { |
||
124 | mkdir($dir, 0777); |
||
125 | } |
||
126 | chmod($dir, 0777); |
||
127 | // Create directory for photo in public album |
||
128 | $dir = XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo'; |
||
129 | if (!is_dir($dir)) { |
||
130 | mkdir($dir, 0777); |
||
131 | } |
||
132 | chmod($dir, 0777); |
||
133 | $dir = XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/original'; |
||
134 | if (!is_dir($dir)) { |
||
135 | mkdir($dir, 0777); |
||
136 | } |
||
137 | chmod($dir, 0777); |
||
138 | $dir = XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/large'; |
||
139 | if (!is_dir($dir)) { |
||
140 | mkdir($dir, 0777); |
||
141 | } |
||
142 | chmod($dir, 0777); |
||
143 | $dir = XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/medium'; |
||
144 | if (!is_dir($dir)) { |
||
145 | mkdir($dir, 0777); |
||
146 | } |
||
147 | chmod($dir, 0777); |
||
148 | $dir = XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/thumb'; |
||
149 | if (!is_dir($dir)) { |
||
150 | mkdir($dir, 0777); |
||
151 | } |
||
152 | chmod($dir, 0777); |
||
153 | |||
154 | |||
155 | |||
156 | // Create directory for photo in user's album |
||
157 | //mkdir(XOOPS_ROOT_PATH."/uploads/extgallery/user-photo"); |
||
158 | |||
159 | // Copy index.html files on uploads folders |
||
160 | $indexFile = XOOPS_ROOT_PATH . '/modules/extgallery/include/index.html'; |
||
161 | copy($indexFile, XOOPS_ROOT_PATH . '/uploads/extgallery/index.html'); |
||
162 | copy($indexFile, XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/index.html'); |
||
163 | copy($indexFile, XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/original/index.html'); |
||
164 | copy($indexFile, XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/large/index.html'); |
||
165 | copy($indexFile, XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/medium/index.html'); |
||
166 | copy($indexFile, XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/thumb/index.html'); |
||
167 | |||
168 | */ |
||
169 | |||
170 | require_once __DIR__ . '/../../../include/cp_header.php'; |
||
171 | |||
172 | |||
173 | $moduleDirName = basename(dirname(__DIR__)); |
||
174 | |||
175 | |||
176 | // $moduleDirName = $xoopsModule->getVar('dirname'); |
||
177 | $configurator = include $GLOBALS['xoops']->path('modules/' . $moduleDirName . '/include/config.php'); |
||
178 | |||
179 | $classUtility = ucfirst($moduleDirName) . 'Utility'; |
||
180 | if (!class_exists($classUtility)) { |
||
181 | xoops_load('utility', $moduleDirName); |
||
182 | } |
||
183 | |||
184 | // require_once __DIR__ . '/config.php'; |
||
185 | |||
186 | if (count($configurator['uploadFolders']) > 0) { |
||
187 | // foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
||
188 | foreach (array_keys($configurator['uploadFolders']) as $i) { |
||
189 | $classUtility::createFolder($configurator['uploadFolders'][$i]); |
||
190 | } |
||
191 | } |
||
192 | View Code Duplication | if (count($configurator['copyFiles']) > 0) { |
|
193 | $file = __DIR__ . '/../assets/images/blank.png'; |
||
194 | foreach (array_keys($configurator['copyFiles']) as $i) { |
||
195 | $dest = $configurator['copyFiles'][$i] . '/blank.png'; |
||
196 | $classUtility::copyFile($file, $dest); |
||
197 | } |
||
198 | } |
||
199 | |||
200 | return true; |
||
201 | } |
||
202 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: