Conditions | 18 |
Paths | 72 |
Total Lines | 69 |
Code Lines | 53 |
Lines | 52 |
Ratio | 75.36 % |
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 |
||
113 | private function resize_gd($src, $width, $height, $quality, $srcImgInfo) { |
||
114 | View Code Duplication | switch ($srcImgInfo['mime']) { |
|
115 | case 'image/gif': |
||
116 | if (@imagetypes() & IMG_GIF) { |
||
117 | $oSrcImg = @imagecreatefromgif($src); |
||
118 | } else { |
||
119 | $ermsg = 'GIF images are not supported'; |
||
120 | } |
||
121 | break; |
||
122 | case 'image/jpeg': |
||
123 | if (@imagetypes() & IMG_JPG) { |
||
124 | $oSrcImg = @imagecreatefromjpeg($src) ; |
||
125 | } else { |
||
126 | $ermsg = 'JPEG images are not supported'; |
||
127 | } |
||
128 | break; |
||
129 | case 'image/png': |
||
130 | if (@imagetypes() & IMG_PNG) { |
||
131 | $oSrcImg = @imagecreatefrompng($src) ; |
||
132 | } else { |
||
133 | $ermsg = 'PNG images are not supported'; |
||
134 | } |
||
135 | break; |
||
136 | case 'image/wbmp': |
||
137 | if (@imagetypes() & IMG_WBMP) { |
||
138 | $oSrcImg = @imagecreatefromwbmp($src); |
||
139 | } else { |
||
140 | $ermsg = 'WBMP images are not supported'; |
||
141 | } |
||
142 | break; |
||
143 | default: |
||
144 | $oSrcImg = false; |
||
145 | $ermsg = $srcImgInfo['mime'].' images are not supported'; |
||
146 | break; |
||
147 | } |
||
148 | |||
149 | if ($oSrcImg && false != ($tmp = imagecreatetruecolor($width, $height))) { |
||
150 | |||
151 | if (!imagecopyresampled($tmp, $oSrcImg, 0, 0, 0, 0, $width, $height, $srcImgInfo[0], $srcImgInfo[1])) { |
||
152 | return false; |
||
153 | } |
||
154 | |||
155 | View Code Duplication | switch ($srcImgInfo['mime']) { |
|
156 | case 'image/gif': |
||
157 | imagegif($tmp, $src); |
||
158 | break; |
||
159 | case 'image/jpeg': |
||
160 | imagejpeg($tmp, $src, $quality); |
||
161 | break; |
||
162 | case 'image/png': |
||
163 | if (function_exists('imagesavealpha') && function_exists('imagealphablending')) { |
||
164 | imagealphablending($tmp, false); |
||
165 | imagesavealpha($tmp, true); |
||
166 | } |
||
167 | imagepng($tmp, $src); |
||
168 | break; |
||
169 | case 'image/wbmp': |
||
170 | imagewbmp($tmp, $src); |
||
171 | break; |
||
172 | } |
||
173 | |||
174 | imagedestroy($oSrcImg); |
||
175 | imagedestroy($tmp); |
||
176 | |||
177 | return true; |
||
178 | |||
179 | } |
||
180 | return false; |
||
181 | } |
||
182 | |||
216 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.