| Conditions | 13 |
| Paths | 31 |
| Total Lines | 48 |
| Code Lines | 31 |
| 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 |
||
| 55 | public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): array |
||
| 56 | { |
||
| 57 | $images = $arguments['images']; |
||
| 58 | |||
| 59 | $result = array('minWidth' => 0, 'minHeight' => 0, |
||
| 60 | 'maxWidth' => 0, 'maxHeight' => 0, |
||
| 61 | 'minRatio' => 0, 'maxRatio' => 0, |
||
| 62 | 'minRatioWidth' => 0, 'minRatioHeight' => 0, |
||
| 63 | 'maxRatioWidth' => 0, 'maxRatioHeight' => 0); |
||
| 64 | |||
| 65 | foreach ($images as $image) { |
||
| 66 | foreach (array('height', 'width') as $type) { |
||
| 67 | $val = self::getCroppedProperty($image, $type); |
||
| 68 | if ($val === null) { |
||
| 69 | continue; |
||
| 70 | } |
||
| 71 | |||
| 72 | $min = 'min' . ucfirst($type); |
||
| 73 | $max = 'max' . ucfirst($type); |
||
| 74 | |||
| 75 | if ($result[$min] == 0 || $result[$min] > $val) { |
||
| 76 | $result[$min] = $val; |
||
| 77 | } |
||
| 78 | |||
| 79 | if ($result[$max] < $val) { |
||
| 80 | $result[$max] = $val; |
||
| 81 | } |
||
| 82 | } |
||
| 83 | $width = self::getCroppedProperty($image, 'width'); |
||
| 84 | $height = self::getCroppedProperty($image, 'height'); |
||
| 85 | if ($width === null || $height === null || $width == 0) { |
||
| 86 | continue; |
||
| 87 | } |
||
| 88 | |||
| 89 | $ratio = $height / $width * 100; |
||
| 90 | if ($result['minRatio'] == 0 || $ratio < $result['minRatio']) { |
||
| 91 | $result['minRatio'] = $ratio; |
||
| 92 | $result['minRatioWidth'] = $width; |
||
| 93 | $result['minRatioHeight'] = $height; |
||
| 94 | } |
||
| 95 | if ($ratio > $result['maxRatio']) { |
||
| 96 | $result['maxRatio'] = $ratio; |
||
| 97 | $result['maxRatioWidth'] = $width; |
||
| 98 | $result['maxRatioHeight'] = $height; |
||
| 99 | } |
||
| 100 | } |
||
| 101 | |||
| 102 | return $result; |
||
|
|
|||
| 103 | } |
||
| 134 |
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: