| Conditions | 17 |
| Paths | 319 |
| Total Lines | 68 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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); |
||
| 25 | protected static function dimension(array $options = [], int $width, int $height): void |
||
| 26 | { |
||
| 27 | $expectedHeight = $options[self::DIMENSION_HEIGHT] ?? false; |
||
| 28 | if ($expectedHeight !== false) { |
||
| 29 | if ($expectedHeight !== $height) { |
||
| 30 | throw new ValidatorException( |
||
| 31 | 'Image height should be exactly ' . $options[self::DIMENSION_HEIGHT] ?? false |
||
|
|
|||
| 32 | ); |
||
| 33 | } |
||
| 34 | } |
||
| 35 | |||
| 36 | $expectedWidth = $options[self::DIMENSION_WIDTH] ?? false; |
||
| 37 | if ($expectedWidth !== false) { |
||
| 38 | if ($expectedWidth !== $width) { |
||
| 39 | throw new ValidatorException( |
||
| 40 | 'Image width should be exactly ' . $expectedWidth |
||
| 41 | ); |
||
| 42 | } |
||
| 43 | } |
||
| 44 | |||
| 45 | $minHeight = $options[self::DIMENSION_MIN_HEIGHT] ?? false; |
||
| 46 | if ($minHeight !== false) { |
||
| 47 | if ($height < $minHeight) { |
||
| 48 | throw new ValidatorException( |
||
| 49 | 'Image height should be at least ' . $minHeight |
||
| 50 | ); |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | $minWidth = $options[self::DIMENSION_MIN_WIDTH] ?? false; |
||
| 55 | if ($minWidth !== false) { |
||
| 56 | if ($width < $minWidth) { |
||
| 57 | throw new ValidatorException( |
||
| 58 | 'Image width should be at least ' . $minWidth |
||
| 59 | ); |
||
| 60 | } |
||
| 61 | } |
||
| 62 | |||
| 63 | $maxHeight = $options[self::DIMENSION_MAX_HEIGHT] ?? false; |
||
| 64 | if ($maxHeight !== false) { |
||
| 65 | if ($height > $maxHeight) { |
||
| 66 | throw new ValidatorException( |
||
| 67 | 'Image height should be at most ' . $maxHeight |
||
| 68 | ); |
||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 72 | $maxWidth = $options[self::DIMENSION_MAX_WIDTH] ?? false; |
||
| 73 | if ($maxWidth !== false) { |
||
| 74 | if ($width > $maxWidth) { |
||
| 75 | throw new ValidatorException( |
||
| 76 | 'Image width should be at most ' . $maxWidth |
||
| 77 | ); |
||
| 78 | } |
||
| 79 | } |
||
| 80 | |||
| 81 | $ratio = $options[self::DIMENSION_RATIO] ?? false; |
||
| 82 | if ($ratio !== false) { |
||
| 83 | if (!$width || !$height) { |
||
| 84 | throw new ValidatorException( |
||
| 85 | 'Zero width or height' |
||
| 86 | ); |
||
| 87 | } |
||
| 88 | $ratio = $width/$height; |
||
| 89 | $expected = $ratio; |
||
| 90 | if (abs(($ratio-$expected)/$expected) > 0.0001) { |
||
| 91 | throw new ValidatorException( |
||
| 92 | 'Image width/height ratio should be ' . $ratio |
||
| 93 | ); |
||
| 144 |