| Conditions | 10 |
| Paths | 4 |
| Total Lines | 28 |
| Code Lines | 18 |
| 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); |
||
| 98 | public static function validate($value, array $options = [], Datatype $datatype, ?Model $model = null) |
||
| 99 | { |
||
| 100 | if ($datatype->getBasetype() !== 'file') { |
||
| 101 | throw new ValidatorException( |
||
| 102 | 'Not a file' |
||
| 103 | ); |
||
| 104 | } |
||
| 105 | |||
| 106 | $imageData = getimagesize($value); |
||
| 107 | if ($imageData === false) { |
||
| 108 | throw new ValidatorException( |
||
| 109 | 'Not an image' |
||
| 110 | ); |
||
| 111 | } |
||
| 112 | |||
| 113 | if (($options[self::DIMENSION_HEIGHT] ?? false) || |
||
| 114 | ($options[self::DIMENSION_WIDTH] ?? false) || |
||
| 115 | ($options[self::DIMENSION_MIN_HEIGHT] ?? false) || |
||
| 116 | ($options[self::DIMENSION_MIN_WIDTH] ?? false) || |
||
| 117 | ($options[self::DIMENSION_MAX_HEIGHT] ?? false) || |
||
| 118 | ($options[self::DIMENSION_MAX_WIDTH] ?? false) || |
||
| 119 | ($options[self::DIMENSION_RATIO] ?? false) |
||
| 120 | ) { |
||
| 121 | $width = $imageData[0]; |
||
| 122 | $height = $imageData[1]; |
||
| 123 | static::dimension($options, $width, $height); |
||
| 124 | } |
||
| 125 | return $value; |
||
| 126 | } |
||
| 144 |