| Conditions | 15 |
| Paths | 104 |
| Total Lines | 56 |
| Code Lines | 39 |
| 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 |
||
| 27 | function sf_attachmentImage($source) |
||
| 28 | { |
||
| 29 | global $xoopsModuleConfig; |
||
| 30 | |||
| 31 | $img_path = XOOPS_ROOT_PATH . '/' . $xoopsModuleConfig['dir_attachments']; |
||
|
|
|||
| 32 | $img_url = XOOPS_URL . '/' . $xoopsModuleConfig['dir_attachments']; |
||
| 33 | $thumb_path = $img_path . '/thumbs'; |
||
| 34 | $thumb_url = $img_url . '/thumbs'; |
||
| 35 | |||
| 36 | $thumb = $thumb_path . '/' . $source; |
||
| 37 | $image = $img_path . '/' . $source; |
||
| 38 | $thumb_url = $thumb_url . '/' . $source; |
||
| 39 | $image_url = $img_url . '/' . $source; |
||
| 40 | |||
| 41 | $imginfo = @getimagesize($image); |
||
| 42 | $img_info = (count($imginfo) > 0) ? $imginfo[0] . 'X' . $imginfo[1] . ' px' : ''; |
||
| 43 | |||
| 44 | if ($xoopsModuleConfig['max_image_width'] > 0 && $xoopsModuleConfig['max_image_height'] > 0) { |
||
| 45 | if ($imginfo[0] > $xoopsModuleConfig['max_image_width'] |
||
| 46 | || $imginfo[1] > $xoopsModuleConfig['max_image_height']) { |
||
| 47 | //if (!file_exists($thumb_path.'/'.$source) && $imginfo[0] > $xoopsModuleConfig['max_img_width']) { |
||
| 48 | if (!file_exists($thumb_path . '/' . $source)) { |
||
| 49 | sf_createThumbnail($source, $xoopsModuleConfig['max_image_width']); |
||
| 50 | } |
||
| 51 | } |
||
| 52 | |||
| 53 | if ($imginfo[0] > $xoopsModuleConfig['max_image_width'] |
||
| 54 | || $imginfo[1] > $xoopsModuleConfig['max_image_height']) { |
||
| 55 | $pseudo_width = $xoopsModuleConfig['max_image_width']; |
||
| 56 | $pseudo_height = $xoopsModuleConfig['max_image_width'] * ($imginfo[1] / $imginfo[0]); |
||
| 57 | $pseudo_size = "width='" . $pseudo_width . "px' height='" . $pseudo_height . "px'"; |
||
| 58 | } |
||
| 59 | // irmtfan to fix Undefined variable: pseudo_height |
||
| 60 | if (!empty($pseudo_height) && $xoopsModuleConfig['max_image_height'] > 0 |
||
| 61 | && $pseudo_height > $xoopsModuleConfig['max_image_height']) { |
||
| 62 | $pseudo_height = $xoopsModuleConfig['max_image_height']; |
||
| 63 | $pseudo_width = $xoopsModuleConfig['max_image_height'] * ($imginfo[0] / $imginfo[1]); |
||
| 64 | $pseudo_size = "width='" . $pseudo_width . "px' height='" . $pseudo_height . "px'"; |
||
| 65 | } |
||
| 66 | } |
||
| 67 | |||
| 68 | if (file_exists($thumb)) { |
||
| 69 | $attachmentImage = '<a href="' . $image_url . '" title="' . $source . ' ' . $img_info . '" target="_blank">'; |
||
| 70 | $attachmentImage .= '<img src="' . $thumb_url . '" alt="' . $source . ' ' . $img_info . '">'; |
||
| 71 | $attachmentImage .= '</a>'; |
||
| 72 | } elseif (!empty($pseudo_size)) { |
||
| 73 | $attachmentImage = '<a href="' . $image_url . '" title="' . $source . ' ' . $img_info . '" target="_blank">'; |
||
| 74 | $attachmentImage .= '<img src="' . $image_url . '" ' . $pseudo_size . ' alt="' . $source . ' ' . $img_info . '">'; |
||
| 75 | $attachmentImage .= '</a>'; |
||
| 76 | } elseif (file_exists($image)) { |
||
| 77 | $attachmentImage = '<img src="' . $image_url . '" alt="' . $source . ' ' . $img_info . '">'; |
||
| 78 | } else { |
||
| 79 | $attachmentImage = ''; |
||
| 80 | } |
||
| 81 | |||
| 82 | return $attachmentImage; |
||
| 83 | } |
||
| 212 |