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