Conditions | 14 |
Paths | 30 |
Total Lines | 87 |
Code Lines | 73 |
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 |
||
226 | public function getFileIconCollection($iconSet) { |
||
227 | |||
228 | $fileIcons = []; |
||
229 | |||
230 | //get all allowed mime types |
||
231 | $helper = \XoopsModules\Wgfilemanager\Helper::getInstance(); |
||
232 | $mimetypeHandler = $helper->getHandler('Mimetype'); |
||
233 | $allowedExtensions = $mimetypeHandler->getExtensionArray(); |
||
234 | |||
235 | $folderPath = ''; |
||
236 | $folderUrl = ''; |
||
237 | $fileTrailing = ''; |
||
238 | $fileDefault = ''; |
||
239 | $fileIcons['type'] = ''; |
||
240 | |||
241 | switch ($iconSet) { |
||
242 | case 'classic': |
||
243 | $folderPath = \WGFILEMANAGER_ICONS_PATH . '/fileicons/file-icon-vectors-master/dist/icons/classic/'; |
||
244 | $folderUrl = \WGFILEMANAGER_ICONS_URL . '/fileicons/file-icon-vectors-master/dist/icons/classic/'; |
||
245 | $fileTrailing = '.svg'; |
||
246 | $fileDefault = 'default.svg'; |
||
247 | $fileIcons['type'] = 'svg'; |
||
248 | break; |
||
249 | case 'high-contrast': |
||
250 | $folderPath = \WGFILEMANAGER_ICONS_PATH . '/fileicons/file-icon-vectors-master/dist/icons/high-contrast/'; |
||
251 | $folderUrl = \WGFILEMANAGER_ICONS_URL . '/fileicons/file-icon-vectors-master/dist/icons/high-contrast/'; |
||
252 | $fileTrailing = '.svg'; |
||
253 | $fileDefault = 'default.svg'; |
||
254 | $fileIcons['type'] = 'svg'; |
||
255 | break; |
||
256 | case 'square-o': |
||
257 | $folderPath = \WGFILEMANAGER_ICONS_PATH . '/fileicons/file-icon-vectors-master/dist/icons/square-o/'; |
||
258 | $folderUrl = \WGFILEMANAGER_ICONS_URL . '/fileicons/file-icon-vectors-master/dist/icons/square-o/'; |
||
259 | $fileTrailing = '.svg'; |
||
260 | $fileDefault = 'default.svg'; |
||
261 | $fileIcons['type'] = 'svg'; |
||
262 | break; |
||
263 | case 'vivid': |
||
264 | $folderPath = \WGFILEMANAGER_ICONS_PATH . '/fileicons/file-icon-vectors-master/dist/icons/vivid/'; |
||
265 | $folderUrl = \WGFILEMANAGER_ICONS_URL . '/fileicons/file-icon-vectors-master/dist/icons/vivid/'; |
||
266 | $fileTrailing = '.svg'; |
||
267 | $fileDefault = 'default.svg'; |
||
268 | $fileIcons['type'] = 'svg'; |
||
269 | break; |
||
270 | case 'teambox': |
||
271 | $folderPath = \WGFILEMANAGER_ICONS_PATH . '/fileicons/free-file-icons-master/512px/'; |
||
272 | $folderUrl = \WGFILEMANAGER_ICONS_URL . '/fileicons/free-file-icons-master/512px/'; |
||
273 | $fileTrailing = '.png'; |
||
274 | $fileDefault = '_blank.png'; |
||
275 | $fileIcons['type'] = 'png'; |
||
276 | break; |
||
277 | case 'eagerterrier': |
||
278 | $folderPath = \WGFILEMANAGER_ICONS_PATH . '/fileicons/mimetypes-link-icons-master/images/'; |
||
279 | $folderUrl = \WGFILEMANAGER_ICONS_URL . '/fileicons/mimetypes-link-icons-master/images/'; |
||
280 | $fileTrailing = '-icon-128x128.png'; |
||
281 | $fileDefault = 'default-128x128.png'; |
||
282 | $fileIcons['type'] = 'png'; |
||
283 | break; |
||
284 | case 'none': |
||
285 | break; |
||
286 | case '': |
||
287 | default: |
||
288 | throw new \Exception('Invalid iconset!'); |
||
289 | } |
||
290 | |||
291 | if ($iconSet == 'none') { |
||
292 | foreach ($allowedExtensions as $allowedExt) { |
||
293 | $fileIcons['files'][$allowedExt['extension']]['src'] = ''; |
||
294 | $fileIcons['files'][$allowedExt['extension']]['category'] = $allowedExt['category']; |
||
295 | } |
||
296 | } else { |
||
297 | if (file_exists($folderPath)) { |
||
298 | foreach ($allowedExtensions as $allowedExt) { |
||
299 | $filePath = $folderPath . $allowedExt['extension'] . $fileTrailing; |
||
300 | if (file_exists($filePath)) { |
||
301 | $fileIcons['files'][$allowedExt['extension']]['src'] = $folderUrl . $allowedExt['extension'] . $fileTrailing; |
||
302 | $fileIcons['files'][$allowedExt['extension']]['category'] = $allowedExt['category']; |
||
303 | } else { |
||
304 | $fileIcons['default'] = $fileDefault; |
||
305 | } |
||
306 | } |
||
307 | } else { |
||
308 | throw new \Exception('Folder ' . $folderPath . ' does not exist!'); |
||
309 | } |
||
310 | } |
||
311 | |||
312 | return $fileIcons; |
||
313 | |||
351 |