Conditions | 4 |
Paths | 8 |
Total Lines | 133 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | 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 |
||
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 XoopsConfigHandler $configHandler */ |
||
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 | $moduleDirName = $xoopsModule->getVar('dirname'); |
||
171 | include_once $GLOBALS['xoops']->path('modules/' . $moduleDirName . '/include/config.php'); |
||
172 | |||
173 | $classUtilities = ucfirst($moduleDirName) . 'Utilities'; |
||
174 | if (!class_exists($classUtilities)) { |
||
175 | xoops_load('utilities', $moduleDirName); |
||
176 | } |
||
177 | |||
178 | |||
179 | foreach (array_keys($uploadFolders) as $i) { |
||
180 | $classUtilities::createFolder($uploadFolders[$i]); |
||
181 | } |
||
182 | |||
183 | $file = PUBLISHER_ROOT_PATH . '/assets/images/blank.png'; |
||
184 | foreach (array_keys($copyFiles) as $i) { |
||
185 | $dest = $copyFiles[$i] . '/blank.png'; |
||
186 | $classUtilities::copyFile($file, $dest); |
||
187 | } |
||
188 | |||
189 | return true; |
||
190 | } |
||
191 |
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: