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