Conditions | 10 |
Paths | 3 |
Total Lines | 44 |
Code Lines | 32 |
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 |
||
69 | function copyImage($srcFile, $destFile, $w, $h, $quality = 100) |
||
70 | { |
||
71 | $tmpSrc = pathinfo(strtolower($srcFile)); |
||
72 | $tmpDest = pathinfo(strtolower($destFile)); |
||
73 | $size = getimagesize($srcFile); |
||
74 | |||
75 | if ($tmpDest['extension'] == 'gif' || $tmpDest['extension'] == 'jpg') { |
||
76 | $destFile = substr_replace($destFile, 'jpg', -3); |
||
77 | $dest = imagecreatetruecolor($w, $h); |
||
78 | //imageantialias($dest, TRUE); |
||
79 | } elseif ($tmpDest['extension'] == 'png') { |
||
80 | $dest = imagecreatetruecolor($w, $h); |
||
81 | //imageantialias($dest, TRUE); |
||
82 | } else { |
||
83 | return false; |
||
84 | } |
||
85 | |||
86 | switch ($size[2]) { |
||
87 | case 1: //GIF |
||
88 | $src = imagecreatefromgif($srcFile); |
||
89 | break; |
||
90 | case 2: //JPEG |
||
91 | $src = imagecreatefromjpeg($srcFile); |
||
92 | break; |
||
93 | case 3: //PNG |
||
94 | $src = imagecreatefrompng($srcFile); |
||
95 | break; |
||
96 | default: |
||
97 | return false; |
||
98 | break; |
||
99 | } |
||
100 | |||
101 | imagecopyresampled($dest, $src, 0, 0, 0, 0, $w, $h, $size[0], $size[1]); |
||
102 | |||
103 | switch ($size[2]) { |
||
104 | case 1: |
||
105 | case 2: |
||
106 | imagejpeg($dest, $destFile, $quality); |
||
107 | break; |
||
108 | case 3: |
||
109 | imagepng($dest, $destFile); |
||
110 | } |
||
111 | |||
112 | return $destFile; |
||
113 | } |
||
114 |