| Conditions | 18 |
| Paths | 256 |
| Total Lines | 64 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| 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 declare(strict_types=1); |
||
| 24 | function newbbAttachmentImage(string $source): string |
||
| 25 | { |
||
| 26 | $pseudo_size = null; |
||
| 27 | $img_path = $GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments']); |
||
| 28 | $img_url = XOOPS_URL . '/' . $GLOBALS['xoopsModuleConfig']['dir_attachments']; |
||
| 29 | $thumb_path = $img_path . '/thumbs'; |
||
| 30 | $thumb_url = $img_url . '/thumbs'; |
||
| 31 | |||
| 32 | $thumb = $thumb_path . '/' . $source; |
||
| 33 | $image = $img_path . '/' . $source; |
||
| 34 | $thumb_url .= '/' . $source; |
||
| 35 | $image_url = $img_url . '/' . $source; |
||
| 36 | $img_info = ''; |
||
|
|
|||
| 37 | |||
| 38 | $imginfo = @getimagesize($image); |
||
| 39 | |||
| 40 | // Change by BigKev73 - Removed the is_array check, otherwise the img_info is never set |
||
| 41 | //if (is_array($image)) { |
||
| 42 | $img_info = (is_array($imginfo) && count($imginfo) > 0) ? $imginfo[0] . 'X' . $imginfo[1] . ' px' : ''; |
||
| 43 | //} |
||
| 44 | |||
| 45 | if (is_array($imginfo) && $GLOBALS['xoopsModuleConfig']['max_image_width'] > 0 |
||
| 46 | && $GLOBALS['xoopsModuleConfig']['max_image_height'] > 0) { |
||
| 47 | if ($imginfo[0] > $GLOBALS['xoopsModuleConfig']['max_image_width'] |
||
| 48 | || $imginfo[1] > $GLOBALS['xoopsModuleConfig']['max_image_height']) { |
||
| 49 | //if (!file_exists($thumb_path.'/'.$source) && $imginfo[0] > $GLOBALS['xoopsModuleConfig']['max_img_width']) { |
||
| 50 | if (!file_exists($thumb_path . '/' . $source)) { |
||
| 51 | newbbCreateThumbnail($source, $GLOBALS['xoopsModuleConfig']['max_image_width']); |
||
| 52 | } |
||
| 53 | } |
||
| 54 | } |
||
| 55 | |||
| 56 | //BigKev73 Change to remove height value |
||
| 57 | |||
| 58 | if (is_array($imginfo) && ($imginfo[0] > $GLOBALS['xoopsModuleConfig']['max_image_width'] |
||
| 59 | || $imginfo[1] > $GLOBALS['xoopsModuleConfig']['max_image_height'])) { |
||
| 60 | $pseudo_width = $GLOBALS['xoopsModuleConfig']['max_image_width']; |
||
| 61 | $pseudo_height = $GLOBALS['xoopsModuleConfig']['max_image_width'] * ($imginfo[1] / $imginfo[0]); |
||
| 62 | $pseudo_size = "width='" . $pseudo_width . "' height='" . $pseudo_height . "'"; |
||
| 63 | } |
||
| 64 | // irmtfan to fix Undefined variable: pseudo_height |
||
| 65 | if (!empty($pseudo_height) && $GLOBALS['xoopsModuleConfig']['max_image_height'] > 0 |
||
| 66 | && $pseudo_height > $GLOBALS['xoopsModuleConfig']['max_image_height']) { |
||
| 67 | $pseudo_height = $GLOBALS['xoopsModuleConfig']['max_image_height']; |
||
| 68 | $pseudo_width = $GLOBALS['xoopsModuleConfig']['max_image_height'] * ($imginfo[0] / $imginfo[1]); |
||
| 69 | $pseudo_size = "width='" . $pseudo_width . "' height='" . $pseudo_height . "'"; |
||
| 70 | } |
||
| 71 | |||
| 72 | //BigKev73 Change to add max with property to properly scale photos |
||
| 73 | if (file_exists($thumb)) { |
||
| 74 | $attachmentImage = '<a href="' . $image_url . '" title="' . $source . ' ' . $img_info . '" target="_blank">'; |
||
| 75 | $attachmentImage .= '<img src="' . $thumb_url . '" ' . $pseudo_size . ' alt="' . $source . ' ' . $img_info . '" style="max-width: 100%; height: auto;">'; |
||
| 76 | $attachmentImage .= '</a>'; |
||
| 77 | } elseif (!empty($pseudo_size)) { |
||
| 78 | $attachmentImage = '<a href="' . $image_url . '" title="' . $source . ' ' . $img_info . '" target="_blank">'; |
||
| 79 | $attachmentImage .= '<img src="' . $image_url . '" ' . $pseudo_size . ' alt="' . $source . ' ' . $img_info . '" style="max-width: 100%; height: auto;">'; |
||
| 80 | $attachmentImage .= '</a>'; |
||
| 81 | } elseif (file_exists($image)) { |
||
| 82 | $attachmentImage = '<img src="' . $image_url . '" alt="' . $source . ' ' . $img_info . '" style="width:' . $imginfo[0] . '" height="' . $imginfo[1] . '" style="max-width: 100%; height: auto;">'; |
||
| 83 | } else { |
||
| 84 | $attachmentImage = ''; |
||
| 85 | } |
||
| 86 | |||
| 87 | return $attachmentImage; |
||
| 88 | } |
||
| 211 |