| Conditions | 26 |
| Paths | 7336 |
| Total Lines | 114 |
| Code Lines | 76 |
| 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 |
||
| 228 | public function resizeImage() |
||
| 229 | { |
||
| 230 | global $xoopsModuleConfig; |
||
| 231 | // $this->_img_info = info array to the image being resized |
||
| 232 | // $this->_img_info[0] == width |
||
| 233 | // $this->_img_info[1] == height |
||
| 234 | // $this->_img_info[2] == is a flag indicating the type of the image: 1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 7 = TIFF(intel byte order), 8 = TIFF(motorola byte order) |
||
| 235 | // $this->_img_info[3] == is a text string with the correct height="yyy" width="xxx" string that can be used directly in an IMG tag |
||
| 236 | /** |
||
| 237 | * Get image size and scale ratio |
||
| 238 | */ |
||
| 239 | $scale = min($this->img_width / $this->_img_info[0], $this->img_height / $this->_img_info[1]); |
||
| 240 | /** |
||
| 241 | * If the image is larger than the max shrink it |
||
| 242 | */ |
||
| 243 | $newWidth = $this->img_width; |
||
| 244 | $newHeight = $this->img_height; |
||
| 245 | if ($scale < 1 && $this->img_aspect == 1) { |
||
| 246 | $newWidth = floor($scale * $this->_img_info[0]); |
||
| 247 | $newHeight = floor($scale * $this->_img_info[1]); |
||
| 248 | } |
||
| 249 | $newWidth = ($newWidth > $this->_img_info[0]) ? $this->_img_info[0] : $newWidth; |
||
| 250 | $newHeight = ($newHeight > $this->_img_info[0]) ? $this->_img_info[0] : $newHeight; |
||
| 251 | /** |
||
| 252 | */ |
||
| 253 | $savefile = "{$newWidth}x{$newHeight}_{$this->_img_name}"; |
||
| 254 | $this->_save_image = "{$this->_save_path}/{$savefile}"; |
||
| 255 | |||
| 256 | if ($this->img_update == 0 && file_exists($this->_save_image)) { |
||
| 257 | if ($this->_return_fullpath == 1) { |
||
| 258 | return $this->_source_url . "/{$this->_img_savepath}/{$savefile}"; |
||
| 259 | } else { |
||
| 260 | return "{$this->_img_savepath}/{$savefile}"; |
||
| 261 | } |
||
| 262 | } |
||
| 263 | |||
| 264 | switch ($this->_image_type) { |
||
| 265 | case 'im': |
||
| 266 | if (!empty($xoopsModuleConfig['path_magick']) && is_dir($xoopsModuleConfig['path_magick'])) { |
||
| 267 | if (preg_match("#[A-Z]:|\\\\#Ai", __FILE__)) { |
||
| 268 | $cur_dir = __DIR__; |
||
| 269 | $src_file_im = '"' . $cur_dir . '\\' . str_replace('/', '\\', $this->_source_image) . '"'; |
||
| 270 | $new_file_im = '"' . $cur_dir . '\\' . str_replace('/', '\\', $this->_save_image) . '"'; |
||
| 271 | } else { |
||
| 272 | $src_file_im = escapeshellarg($this->_source_image); |
||
| 273 | $new_file_im = escapeshellarg($this->_save_image); |
||
| 274 | } |
||
| 275 | $magick_command = $xoopsModuleConfig['path_magick'] . '/convert -quality {$xoopsModuleConfig["imagequality"]} -antialias -sample {$newWidth}x{$newHeight} {$src_file_im} +profile "*" ' . str_replace('\\', '/', $new_file_im) . ''; |
||
| 276 | passthru($magick_command); |
||
| 277 | |||
| 278 | return $this->_source_url . "/{$this->_img_savepath}/{$savefile}"; |
||
| 279 | } else { |
||
| 280 | return false; |
||
| 281 | } |
||
| 282 | |||
| 283 | break; |
||
| 284 | |||
| 285 | case 'gd1': |
||
| 286 | case 'gd2': |
||
| 287 | default: |
||
| 288 | |||
| 289 | $imageCreateFunction = (function_exists('imagecreatetruecolor') |
||
| 290 | && $this->_image_type === 'gd2') ? 'imagecreatetruecolor' : 'imagecreate'; |
||
| 291 | $imageCopyfunction = (function_exists('imagecopyresampled') |
||
| 292 | && $this->_image_type === 'gd2') ? 'imagecopyresampled' : 'imagecopyresized'; |
||
| 293 | |||
| 294 | switch ($this->_img_info[2]) { |
||
| 295 | case 1: |
||
| 296 | // GIF image |
||
| 297 | $img = function_exists('imagecreatefromgif') ? imagecreatefromgif($this->_source_image) : imagecreatefrompng($this->_source_image); |
||
| 298 | $tmp_img = $imageCreateFunction($newWidth, $newHeight); |
||
| 299 | $imageCopyfunction($tmp_img, $img, 0, 0, 0, 0, $newWidth, $newHeight, $this->_img_info[0], $this->_img_info[1]); |
||
| 300 | if (function_exists('imagegif')) { |
||
| 301 | imagegif($tmp_img, $this->_save_image); |
||
| 302 | } else { |
||
| 303 | imagepng($tmp_img, $this->_save_image); |
||
| 304 | } |
||
| 305 | imagedestroy($tmp_img); |
||
| 306 | break; |
||
| 307 | |||
| 308 | case 2: |
||
| 309 | // echo $this->_save_image; |
||
| 310 | $img = function_exists('imagecreatefromjpeg') ? imagecreatefromjpeg($this->_source_image) : imagecreatefrompng($this->_source_image); |
||
| 311 | $tmp_img = $imageCreateFunction($newWidth, $newHeight); |
||
| 312 | $imageCopyfunction($tmp_img, $img, 0, 0, 0, 0, $newWidth, $newHeight, $this->_img_info[0], $this->_img_info[1]); |
||
| 313 | if (function_exists('imagejpeg')) { |
||
| 314 | imagejpeg($tmp_img, $this->_save_image, $this->img_quality); |
||
| 315 | } else { |
||
| 316 | imagepng($tmp_img, $this->_save_image); |
||
| 317 | } |
||
| 318 | imagedestroy($tmp_img); |
||
| 319 | break; |
||
| 320 | |||
| 321 | case 3: |
||
| 322 | // PNG image |
||
| 323 | $img = imagecreatefrompng($this->_source_image); |
||
| 324 | $tmp_img = $imageCreateFunction($newWidth, $newHeight); |
||
| 325 | $imageCopyfunction($tmp_img, $img, 0, 0, 0, 0, $newWidth, $newHeight, $this->_img_info[0], $this->_img_info[1]); |
||
| 326 | imagepng($tmp_img, $this->_save_image); |
||
| 327 | imagedestroy($tmp_img); |
||
| 328 | break; |
||
| 329 | default: |
||
| 330 | return false; |
||
| 331 | } |
||
| 332 | if ($this->_return_fullpath == 1) { |
||
| 333 | return $this->_source_url . "/{$this->_img_savepath}/{$savefile}"; |
||
| 334 | } else { |
||
| 335 | return "{$this->_img_savepath}/{$savefile}"; |
||
| 336 | } |
||
| 337 | break; |
||
| 338 | } |
||
| 339 | |||
| 340 | return false; |
||
| 341 | } |
||
| 342 | |||
| 405 |
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.