Refactor big switch to lookup in array. A bit cleaner/codacy happier.

This commit is contained in:
Daniel Meltzer 2020-05-23 12:17:56 -04:00
parent fe74394ae6
commit 4fef065010
No known key found for this signature in database
GPG key ID: 91C5C7B09A5B1CA0

View file

@ -606,38 +606,32 @@ class Helper
$extension = substr(strrchr($filename,'.'),1); $extension = substr(strrchr($filename,'.'),1);
if ($extension) { $allowedExtensionMap = [
switch ($extension) { // Images
case 'jpg': 'jpg' => 'fa fa-file-image-o',
case 'jpeg': 'jpeg' => 'fa fa-file-image-o',
case 'gif': 'gif' => 'fa fa-file-image-o',
case 'png': 'png' => 'fa fa-file-image-o',
return "fa fa-file-image-o"; // word
break; 'doc' => 'fa fa-file-word-o',
case 'doc': 'docx' => 'fa fa-file-word-o',
case 'docx': // Excel
return "fa fa-file-word-o"; 'xls' => 'fa fa-file-excel-o',
break; 'xlsx' => 'fa fa-file-excel-o',
case 'xls': // archive
case 'xlsx': 'zip' => 'fa fa-file-archive-o',
return "fa fa-file-excel-o"; 'rar' => 'fa fa-file-archive-o',
break; //Text
case 'zip': 'txt' => 'fa fa-file-text-o',
case 'rar': 'rtf' => 'fa fa-file-text-o',
return "fa fa-file-archive-o"; 'xml' => 'fa fa-file-text-o',
break; // Misc
case 'pdf': 'pdf' => 'fa fa-file-pdf-o',
return "fa fa-file-pdf-o"; 'lic' => 'fa fa-file-floppy-o',
break; ];
case 'txt':
return "fa fa-file-text-o"; if ($extension && array_key_exists($extension, $allowedExtensionMap)) {
break; return $allowedExtensionMap[$extension];
case 'lic':
return "fa fa-floppy-o";
break;
default:
return "fa fa-file-o";
}
} }
return "fa fa-file-o"; return "fa fa-file-o";
} }