Conditions | 16 |
Paths | 16 |
Total Lines | 32 |
Code Lines | 24 |
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 |
||
38 | public static function guess($filePath) |
||
39 | { |
||
40 | $fileExtension = pathinfo($filePath, PATHINFO_EXTENSION); |
||
41 | $fileExtension = strtolower($fileExtension); |
||
42 | |||
43 | switch ($fileExtension) { |
||
44 | case 'bmp': |
||
45 | case 'gif': |
||
46 | case 'jpeg': |
||
47 | case 'png': |
||
48 | case 'tiff': |
||
49 | case 'webp': |
||
50 | return 'image/' . $fileExtension; |
||
51 | |||
52 | case 'ico': |
||
53 | return 'image/vnd.microsoft.icon'; // or perhaps 'x-icon' ? |
||
54 | |||
55 | case 'jpg': |
||
56 | return 'image/jpeg'; |
||
57 | |||
58 | case 'svg': |
||
59 | return 'image/svg+xml'; |
||
60 | |||
61 | case 'tif': |
||
62 | return 'image/tiff'; |
||
63 | |||
64 | case 'txt': |
||
65 | case 'doc': |
||
66 | case 'exe': |
||
67 | case 'zip': |
||
68 | case 'gz': |
||
69 | return false; |
||
70 | |||
74 |