| Conditions | 10 |
| Paths | 49 |
| Total Lines | 47 |
| Code Lines | 39 |
| 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 |
||
| 51 | private function rotate_gd($path, $orientation) { |
||
| 52 | $imgInfo = getimagesize($path); |
||
| 53 | switch ($imgInfo[2]) { |
||
| 54 | case 1: |
||
| 55 | $image = imagecreatefromgif($path); |
||
| 56 | break; |
||
| 57 | case 2: |
||
| 58 | $image = imagecreatefromjpeg($path); |
||
| 59 | break; |
||
| 60 | case 3: |
||
| 61 | $image = imagecreatefrompng($path); |
||
| 62 | break; |
||
| 63 | default: |
||
| 64 | return false; |
||
| 65 | } |
||
| 66 | |||
| 67 | switch ($orientation) { |
||
| 68 | case 3: |
||
| 69 | $image = imagerotate($image, 180, 0); |
||
| 70 | break; |
||
| 71 | case 6: |
||
| 72 | $image = imagerotate($image, -90, 0); |
||
| 73 | break; |
||
| 74 | case 8: |
||
| 75 | $image = imagerotate($image, 90, 0); |
||
| 76 | break; |
||
| 77 | } |
||
| 78 | |||
| 79 | switch ($imgInfo[2]) { |
||
| 80 | case 1: |
||
| 81 | imagegif($image, $path); |
||
| 82 | break; |
||
| 83 | case 2: |
||
| 84 | imagejpeg($image, $path, 100); |
||
| 85 | break; |
||
| 86 | case 3: |
||
| 87 | imagepng($image, $path); |
||
| 88 | break; |
||
| 89 | default: |
||
| 90 | imagedestroy($image); |
||
| 91 | return false; |
||
| 92 | } |
||
| 93 | |||
| 94 | imagedestroy($image); |
||
| 95 | |||
| 96 | return true; |
||
| 97 | } |
||
| 98 | } |