| Conditions | 2 |
| Paths | 2 |
| Total Lines | 200 |
| Code Lines | 194 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 28 | public function getMimeTypeByExtension($file) { |
||
| 29 | // THX to |
||
| 30 | // http://stackoverflow.com/questions/134833/how-do-i-find-the-mime-type-of-a-file-with-php |
||
| 31 | // MIME types array |
||
| 32 | $mimeTypes = [ |
||
| 33 | '323' => 'text/h323', |
||
| 34 | 'acx' => 'application/internet-property-stream', |
||
| 35 | 'ai' => 'application/postscript', |
||
| 36 | 'aif' => 'audio/x-aiff', |
||
| 37 | 'aifc' => 'audio/x-aiff', |
||
| 38 | 'aiff' => 'audio/x-aiff', |
||
| 39 | 'asf' => 'video/x-ms-asf', |
||
| 40 | 'asr' => 'video/x-ms-asf', |
||
| 41 | 'asx' => 'video/x-ms-asf', |
||
| 42 | 'au' => 'audio/basic', |
||
| 43 | 'avi' => 'video/x-msvideo', |
||
| 44 | 'axs' => 'application/olescript', |
||
| 45 | 'bas' => 'text/plain', |
||
| 46 | 'bcpio' => 'application/x-bcpio', |
||
| 47 | 'bin' => 'application/octet-stream', |
||
| 48 | 'bmp' => 'image/bmp', |
||
| 49 | 'c' => 'text/plain', |
||
| 50 | 'cat' => 'application/vnd.ms-pkiseccat', |
||
| 51 | 'cdf' => 'application/x-cdf', |
||
| 52 | 'cer' => 'application/x-x509-ca-cert', |
||
| 53 | 'class' => 'application/octet-stream', |
||
| 54 | 'clp' => 'application/x-msclip', |
||
| 55 | 'cmx' => 'image/x-cmx', |
||
| 56 | 'cod' => 'image/cis-cod', |
||
| 57 | 'cpio' => 'application/x-cpio', |
||
| 58 | 'crd' => 'application/x-mscardfile', |
||
| 59 | 'crl' => 'application/pkix-crl', |
||
| 60 | 'crt' => 'application/x-x509-ca-cert', |
||
| 61 | 'csh' => 'application/x-csh', |
||
| 62 | 'css' => 'text/css', |
||
| 63 | 'dcr' => 'application/x-director', |
||
| 64 | 'der' => 'application/x-x509-ca-cert', |
||
| 65 | 'dir' => 'application/x-director', |
||
| 66 | 'dll' => 'application/x-msdownload', |
||
| 67 | 'dms' => 'application/octet-stream', |
||
| 68 | 'doc' => 'application/msword', |
||
| 69 | 'dot' => 'application/msword', |
||
| 70 | 'dvi' => 'application/x-dvi', |
||
| 71 | 'dxr' => 'application/x-director', |
||
| 72 | 'eps' => 'application/postscript', |
||
| 73 | 'etx' => 'text/x-setext', |
||
| 74 | 'evy' => 'application/envoy', |
||
| 75 | 'exe' => 'application/octet-stream', |
||
| 76 | 'fif' => 'application/fractals', |
||
| 77 | 'flr' => 'x-world/x-vrml', |
||
| 78 | 'gif' => 'image/gif', |
||
| 79 | 'gtar' => 'application/x-gtar', |
||
| 80 | 'gz' => 'application/x-gzip', |
||
| 81 | 'h' => 'text/plain', |
||
| 82 | 'hdf' => 'application/x-hdf', |
||
| 83 | 'hlp' => 'application/winhlp', |
||
| 84 | 'hqx' => 'application/mac-binhex40', |
||
| 85 | 'hta' => 'application/hta', |
||
| 86 | 'htc' => 'text/x-component', |
||
| 87 | 'htm' => 'text/html', |
||
| 88 | 'html' => 'text/html', |
||
| 89 | 'htt' => 'text/webviewhtml', |
||
| 90 | 'ico' => 'image/x-icon', |
||
| 91 | 'ief' => 'image/ief', |
||
| 92 | 'iii' => 'application/x-iphone', |
||
| 93 | 'ins' => 'application/x-internet-signup', |
||
| 94 | 'isp' => 'application/x-internet-signup', |
||
| 95 | 'jfif' => 'image/pipeg', |
||
| 96 | 'jpe' => 'image/jpeg', |
||
| 97 | 'jpeg' => 'image/jpeg', |
||
| 98 | 'jpg' => 'image/jpeg', |
||
| 99 | 'js' => 'application/x-javascript', |
||
| 100 | 'latex' => 'application/x-latex', |
||
| 101 | 'lha' => 'application/octet-stream', |
||
| 102 | 'lsf' => 'video/x-la-asf', |
||
| 103 | 'lsx' => 'video/x-la-asf', |
||
| 104 | 'lzh' => 'application/octet-stream', |
||
| 105 | 'm13' => 'application/x-msmediaview', |
||
| 106 | 'm14' => 'application/x-msmediaview', |
||
| 107 | 'm3u' => 'audio/x-mpegurl', |
||
| 108 | 'man' => 'application/x-troff-man', |
||
| 109 | 'mdb' => 'application/x-msaccess', |
||
| 110 | 'me' => 'application/x-troff-me', |
||
| 111 | 'mht' => 'message/rfc822', |
||
| 112 | 'mhtml' => 'message/rfc822', |
||
| 113 | 'mid' => 'audio/mid', |
||
| 114 | 'mny' => 'application/x-msmoney', |
||
| 115 | 'mov' => 'video/quicktime', |
||
| 116 | 'movie' => 'video/x-sgi-movie', |
||
| 117 | 'mp2' => 'video/mpeg', |
||
| 118 | 'mp3' => 'audio/mpeg', |
||
| 119 | 'mpa' => 'video/mpeg', |
||
| 120 | 'mpe' => 'video/mpeg', |
||
| 121 | 'mpeg' => 'video/mpeg', |
||
| 122 | 'mpg' => 'video/mpeg', |
||
| 123 | 'mpp' => 'application/vnd.ms-project', |
||
| 124 | 'mpv2' => 'video/mpeg', |
||
| 125 | 'ms' => 'application/x-troff-ms', |
||
| 126 | 'mvb' => 'application/x-msmediaview', |
||
| 127 | 'nws' => 'message/rfc822', |
||
| 128 | 'oda' => 'application/oda', |
||
| 129 | 'p10' => 'application/pkcs10', |
||
| 130 | 'p12' => 'application/x-pkcs12', |
||
| 131 | 'p7b' => 'application/x-pkcs7-certificates', |
||
| 132 | 'p7c' => 'application/x-pkcs7-mime', |
||
| 133 | 'p7m' => 'application/x-pkcs7-mime', |
||
| 134 | 'p7r' => 'application/x-pkcs7-certreqresp', |
||
| 135 | 'p7s' => 'application/x-pkcs7-signature', |
||
| 136 | 'pbm' => 'image/x-portable-bitmap', |
||
| 137 | 'pdf' => 'application/pdf', |
||
| 138 | 'pfx' => 'application/x-pkcs12', |
||
| 139 | 'pgm' => 'image/x-portable-graymap', |
||
| 140 | 'pko' => 'application/ynd.ms-pkipko', |
||
| 141 | 'pma' => 'application/x-perfmon', |
||
| 142 | 'pmc' => 'application/x-perfmon', |
||
| 143 | 'pml' => 'application/x-perfmon', |
||
| 144 | 'pmr' => 'application/x-perfmon', |
||
| 145 | 'pmw' => 'application/x-perfmon', |
||
| 146 | 'pnm' => 'image/x-portable-anymap', |
||
| 147 | 'pot' => 'application/vnd.ms-powerpoint', |
||
| 148 | 'ppm' => 'image/x-portable-pixmap', |
||
| 149 | 'pps' => 'application/vnd.ms-powerpoint', |
||
| 150 | 'ppt' => 'application/vnd.ms-powerpoint', |
||
| 151 | 'prf' => 'application/pics-rules', |
||
| 152 | 'ps' => 'application/postscript', |
||
| 153 | 'pub' => 'application/x-mspublisher', |
||
| 154 | 'qt' => 'video/quicktime', |
||
| 155 | 'ra' => 'audio/x-pn-realaudio', |
||
| 156 | 'ram' => 'audio/x-pn-realaudio', |
||
| 157 | 'ras' => 'image/x-cmu-raster', |
||
| 158 | 'rgb' => 'image/x-rgb', |
||
| 159 | 'rmi' => 'audio/mid', |
||
| 160 | 'roff' => 'application/x-troff', |
||
| 161 | 'rtf' => 'application/rtf', |
||
| 162 | 'rtx' => 'text/richtext', |
||
| 163 | 'scd' => 'application/x-msschedule', |
||
| 164 | 'sct' => 'text/scriptlet', |
||
| 165 | 'setpay' => 'application/set-payment-initiation', |
||
| 166 | 'setreg' => 'application/set-registration-initiation', |
||
| 167 | 'sh' => 'application/x-sh', |
||
| 168 | 'shar' => 'application/x-shar', |
||
| 169 | 'sit' => 'application/x-stuffit', |
||
| 170 | 'snd' => 'audio/basic', |
||
| 171 | 'spc' => 'application/x-pkcs7-certificates', |
||
| 172 | 'spl' => 'application/futuresplash', |
||
| 173 | 'src' => 'application/x-wais-source', |
||
| 174 | 'sst' => 'application/vnd.ms-pkicertstore', |
||
| 175 | 'stl' => 'application/vnd.ms-pkistl', |
||
| 176 | 'stm' => 'text/html', |
||
| 177 | 'svg' => 'image/svg+xml', |
||
| 178 | 'sv4cpio' => 'application/x-sv4cpio', |
||
| 179 | 'sv4crc' => 'application/x-sv4crc', |
||
| 180 | 't' => 'application/x-troff', |
||
| 181 | 'tar' => 'application/x-tar', |
||
| 182 | 'tcl' => 'application/x-tcl', |
||
| 183 | 'tex' => 'application/x-tex', |
||
| 184 | 'texi' => 'application/x-texinfo', |
||
| 185 | 'texinfo' => 'application/x-texinfo', |
||
| 186 | 'tgz' => 'application/x-compressed', |
||
| 187 | 'tif' => 'image/tiff', |
||
| 188 | 'tiff' => 'image/tiff', |
||
| 189 | 'tr' => 'application/x-troff', |
||
| 190 | 'trm' => 'application/x-msterminal', |
||
| 191 | 'tsv' => 'text/tab-separated-values', |
||
| 192 | 'txt' => 'text/plain', |
||
| 193 | 'uls' => 'text/iuls', |
||
| 194 | 'ustar' => 'application/x-ustar', |
||
| 195 | 'vcf' => 'text/x-vcard', |
||
| 196 | 'vrml' => 'x-world/x-vrml', |
||
| 197 | 'wav' => 'audio/x-wav', |
||
| 198 | 'wcm' => 'application/vnd.ms-works', |
||
| 199 | 'wdb' => 'application/vnd.ms-works', |
||
| 200 | 'wks' => 'application/vnd.ms-works', |
||
| 201 | 'wmf' => 'application/x-msmetafile', |
||
| 202 | 'wps' => 'application/vnd.ms-works', |
||
| 203 | 'wri' => 'application/x-mswrite', |
||
| 204 | 'wrl' => 'x-world/x-vrml', |
||
| 205 | 'wrz' => 'x-world/x-vrml', |
||
| 206 | 'xaf' => 'x-world/x-vrml', |
||
| 207 | 'xbm' => 'image/x-xbitmap', |
||
| 208 | 'xla' => 'application/vnd.ms-excel', |
||
| 209 | 'xlc' => 'application/vnd.ms-excel', |
||
| 210 | 'xlm' => 'application/vnd.ms-excel', |
||
| 211 | 'xls' => 'application/vnd.ms-excel', |
||
| 212 | 'xlsx' => 'vnd.ms-excel', |
||
| 213 | 'xlt' => 'application/vnd.ms-excel', |
||
| 214 | 'xlw' => 'application/vnd.ms-excel', |
||
| 215 | 'xof' => 'x-world/x-vrml', |
||
| 216 | 'xpm' => 'image/x-xpixmap', |
||
| 217 | 'xwd' => 'image/x-xwindowdump', |
||
| 218 | 'z' => 'application/x-compress', |
||
| 219 | 'zip' => 'application/zip', |
||
| 220 | // Added |
||
| 221 | 'png' => 'image/png', |
||
| 222 | ]; |
||
| 223 | $exploded = explode('.', $file); |
||
| 224 | $extension = end($exploded); |
||
| 225 | $extension = strtolower($extension); |
||
| 226 | return isset($mimeTypes[$extension]) ? $mimeTypes[$extension] : 'application/octet-stream'; |
||
| 227 | } |
||
| 228 | |||
| 269 | } |
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.