| Conditions | 26 |
| Paths | 7336 |
| Total Lines | 100 |
| Code Lines | 73 |
| Lines | 50 |
| Ratio | 50 % |
| Changes | 4 | ||
| 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 |
||
| 212 | public function resizeThumbnail() |
||
| 213 | { |
||
| 214 | // Get image size and scale ratio |
||
| 215 | $scale = min($this->img_width / $this->_img_info[0], $this->img_height / $this->_img_info[1]); |
||
| 216 | // If the image is larger than the max shrink it |
||
| 217 | $newWidth = $this->img_width; |
||
| 218 | $newHeight = $this->img_height; |
||
| 219 | if ($scale < 1 && 1 == $this->img_aspect) { |
||
| 220 | $newWidth = floor($scale * $this->_img_info[0]); |
||
| 221 | $newHeight = floor($scale * $this->_img_info[1]); |
||
| 222 | } |
||
| 223 | $newWidth = ($newWidth > $this->_img_info[0]) ? $this->_img_info[0] : $newWidth; |
||
| 224 | $newHeight = ($newHeight > $this->_img_info[0]) ? $this->_img_info[0] : $newHeight; |
||
| 225 | |||
| 226 | $savefile = "{$newWidth}x{$newHeight}_{$this->_imgName}"; |
||
| 227 | $this->_save_image = "{$this->_save_path}/{$savefile}"; |
||
| 228 | |||
| 229 | if (0 == $this->img_update && file_exists($this->_save_image)) { |
||
| 230 | return $this->_return_fullpath == 1 ? $this->_source_url . "/{$this->_img_savepath}/{$savefile}" : "{$this->_img_savepath}/{$savefile}"; |
||
| 231 | } |
||
| 232 | |||
| 233 | switch ($this->_image_type) { |
||
| 234 | case 'im': |
||
| 235 | if (!empty($GLOBALS['xoopsModuleConfig']['path_magick']) && is_dir($GLOBALS['xoopsModuleConfig']['path_magick'])) { |
||
| 236 | if (preg_match("#[A-Z]:|\\\\#Ai", __FILE__)) { |
||
| 237 | $cur_dir = __DIR__; |
||
| 238 | $src_file_im = '"' . $cur_dir . '\\' . strtr($this->_source_image, '/', '\\') . '"'; |
||
| 239 | $new_file_im = '"' . $cur_dir . '\\' . strtr($this->_save_image, '/', '\\') . '"'; |
||
| 240 | } else { |
||
| 241 | $src_file_im = escapeshellarg($this->_source_image); |
||
| 242 | $new_file_im = escapeshellarg($this->_save_image); |
||
| 243 | } |
||
| 244 | $magick_command = $GLOBALS['xoopsModuleConfig']['path_magick'] |
||
| 245 | . '/convert -quality {$GLOBALS["xoopsModuleConfig"]["imagequality"]} -antialias -sample {$newWidth}x{$newHeight} {$src_file_im} +profile "*" ' . str_replace('\\', |
||
| 246 | '/', |
||
| 247 | $new_file_im) |
||
| 248 | . ''; |
||
| 249 | passthru($magick_command); |
||
| 250 | |||
| 251 | return $this->_source_url . "/{$this->_img_savepath}/{$savefile}"; |
||
| 252 | } else { |
||
| 253 | return false; |
||
| 254 | } |
||
| 255 | |||
| 256 | break; |
||
| 257 | |||
| 258 | case 'gd1': |
||
| 259 | case 'gd2': |
||
| 260 | default : |
||
| 261 | |||
| 262 | $imageCreateFunction = (function_exists('imagecreatetruecolor') && 'gd2' == $this->_image_type) ? 'imagecreatetruecolor' : 'imagecreate'; |
||
| 263 | $imageCopyfunction = (function_exists('ImageCopyResampled') && 'gd2' == $this->_image_type) ? 'imagecopyresampled' : 'imagecopyresized'; |
||
| 264 | |||
| 265 | switch ($this->_img_info[2]) { |
||
| 266 | View Code Duplication | case 1: |
|
| 267 | // GIF image |
||
| 268 | $img = function_exists('imagecreatefromgif') ? imagecreatefromgif($this->_source_image) : imagecreatefrompng($this->_source_image); |
||
| 269 | $tmp_img = $imageCreateFunction($newWidth, $newHeight); |
||
| 270 | $imageCopyfunction($tmp_img, $img, 0, 0, 0, 0, $newWidth, $newHeight, $this->_img_info[0], $this->_img_info[1]); |
||
| 271 | if (function_exists('imagegif')) { |
||
| 272 | imagegif($tmp_img, $this->_save_image); |
||
| 273 | } else { |
||
| 274 | imagepng($tmp_img, $this->_save_image); |
||
| 275 | } |
||
| 276 | imagedestroy($tmp_img); |
||
| 277 | break; |
||
| 278 | |||
| 279 | View Code Duplication | case 2: |
|
| 280 | // echo $this->_save_image; |
||
| 281 | $img = function_exists('imagecreatefromjpeg') ? imagecreatefromjpeg($this->_source_image) : imagecreatefrompng($this->_source_image); |
||
| 282 | $tmp_img = $imageCreateFunction($newWidth, $newHeight); |
||
| 283 | $imageCopyfunction($tmp_img, $img, 0, 0, 0, 0, $newWidth, $newHeight, $this->_img_info[0], $this->_img_info[1]); |
||
| 284 | if (function_exists('imagejpeg')) { |
||
| 285 | imagejpeg($tmp_img, $this->_save_image, $this->img_quality); |
||
| 286 | } else { |
||
| 287 | imagepng($tmp_img, $this->_save_image); |
||
| 288 | } |
||
| 289 | imagedestroy($tmp_img); |
||
| 290 | break; |
||
| 291 | |||
| 292 | case 3: |
||
| 293 | // PNG image |
||
| 294 | $img = imagecreatefrompng($this->_source_image); |
||
| 295 | $tmp_img = $imageCreateFunction($newWidth, $newHeight); |
||
| 296 | $imageCopyfunction($tmp_img, $img, 0, 0, 0, 0, $newWidth, $newHeight, $this->_img_info[0], $this->_img_info[1]); |
||
| 297 | imagepng($tmp_img, $this->_save_image); |
||
| 298 | imagedestroy($tmp_img); |
||
| 299 | break; |
||
| 300 | default: |
||
| 301 | return false; |
||
| 302 | } |
||
| 303 | if (1 == $this->_return_fullpath) { |
||
| 304 | return $this->_source_url . "/{$this->_img_savepath}/{$savefile}"; |
||
| 305 | } else { |
||
| 306 | return "{$this->_img_savepath}/{$savefile}"; |
||
| 307 | } |
||
| 308 | break; |
||
| 309 | } |
||
| 310 | // return FALSE; |
||
| 311 | } |
||
| 312 | |||
| 377 |
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.