Conditions | 25 |
Paths | 290 |
Total Lines | 99 |
Code Lines | 67 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
Bugs | 1 | 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 |
||
39 | public static function get_image_link($image, string $name, ?bool $useRetina = null, ?bool $forMobile = null, ?int $resizeToWidth = 0): string |
||
40 | { |
||
41 | $cacheKey = |
||
42 | implode( |
||
43 | '_', |
||
44 | array_filter( |
||
45 | [ |
||
46 | $image->ID, |
||
47 | $name, |
||
48 | ($useRetina ? 'Y' : 'N'), |
||
49 | ($forMobile ? 'MY' : 'MN'), |
||
50 | $resizeToWidth |
||
51 | ] |
||
52 | ) |
||
53 | ); |
||
54 | if (empty(self::$imageLinkCache[$cacheKey])) { |
||
55 | $item = DataObject::get_one(PerfectCMSImageCache::class, ['Code' => $cacheKey]); |
||
56 | if ($item) { |
||
57 | return $item->Link; |
||
58 | } |
||
59 | $link = ''; |
||
60 | //work out perfect width and height |
||
61 | if (null === $useRetina) { |
||
62 | $useRetina = PerfectCMSImages::use_retina($name); |
||
63 | } |
||
64 | |||
65 | $crop = PerfectCMSImages::is_crop($name); |
||
66 | |||
67 | $multiplier = PerfectCMSImages::get_multiplier($useRetina); |
||
68 | $perfectWidth = (int) PerfectCMSImages::get_width($name, true); |
||
69 | $perfectHeight = (int) PerfectCMSImages::get_height($name, true); |
||
70 | |||
71 | if ($forMobile) { |
||
72 | $perfectWidth = (int) PerfectCMSImages::get_mobile_width($name, true); |
||
73 | $perfectHeight = (int) PerfectCMSImages::get_mobile_height($name, true); |
||
74 | } |
||
75 | |||
76 | $perfectWidth *= $multiplier; |
||
77 | $perfectHeight *= $multiplier; |
||
78 | |||
79 | //get current width and height |
||
80 | $myWidth = $image->getWidth(); |
||
81 | $myHeight = $image->getHeight(); |
||
82 | //if we are trying to resize to a width that is small than the perfect width |
||
83 | //and the resize width is small than the current width, then lets resize... |
||
84 | if (0 !== (int) $resizeToWidth) { |
||
85 | if ($resizeToWidth < $perfectWidth && $resizeToWidth < $myWidth) { |
||
86 | $perfectWidth = $resizeToWidth; |
||
87 | } |
||
88 | } |
||
89 | |||
90 | $tmpImage = null; |
||
91 | if ($perfectWidth && $perfectHeight) { |
||
92 | //if the height or the width are already perfect then we can not do anything about it. |
||
93 | if ($myWidth === $perfectWidth && $myHeight === $perfectHeight) { |
||
94 | $tmpImage = $image; |
||
95 | } elseif ($myWidth < $perfectWidth || $myHeight < $perfectHeight) { |
||
96 | $tmpImage = $image->Pad( |
||
97 | $perfectWidth, |
||
98 | $perfectHeight, |
||
99 | PerfectCMSImages::get_padding_bg_colour($name) |
||
100 | ); |
||
101 | } elseif ($crop) { |
||
102 | $tmpImage = $image->Fill($perfectWidth, $perfectHeight); |
||
103 | } else { |
||
104 | $tmpImage = $image->FitMax($perfectWidth, $perfectHeight); |
||
105 | } |
||
106 | } elseif ($perfectWidth) { |
||
107 | if ($myWidth === $perfectWidth) { |
||
108 | $tmpImage = $image; |
||
109 | } elseif ($crop) { |
||
110 | $tmpImage = $image->Fill($perfectWidth, $myHeight); |
||
111 | } else { |
||
112 | $tmpImage = $image->ScaleWidth($perfectWidth); |
||
113 | } |
||
114 | } elseif ($perfectHeight) { |
||
115 | if ($myHeight === $perfectHeight) { |
||
116 | $tmpImage = $image; |
||
117 | } elseif ($crop) { |
||
118 | $tmpImage = $image->Fill($myWidth, $perfectHeight); |
||
119 | } else { |
||
120 | $tmpImage = $image->ScaleHeight($perfectHeight); |
||
121 | } |
||
122 | } elseif ($forMobile) { |
||
123 | // todo: expplain this! |
||
124 | // basically, it is for mobile and there is not perfect height nor width |
||
125 | $tmpImage = null; |
||
126 | } else { |
||
127 | $tmpImage = $image; |
||
128 | } |
||
129 | $link = ''; |
||
130 | if($tmpImage) { |
||
131 | $link = (string) $tmpImage->getUrl(); |
||
132 | } |
||
133 | self::$imageLinkCache[$cacheKey] = $link; |
||
134 | PerfectCMSImageCache::add_one($cacheKey, $link); |
||
135 | } |
||
136 | |||
137 | return self::$imageLinkCache[$cacheKey]; |
||
138 | } |
||
274 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths