| Conditions | 16 |
| Paths | 256 |
| Total Lines | 38 |
| 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 |
||
| 23 | public function load(ImageInterface $image, array $options = []) |
||
| 24 | { |
||
| 25 | $mode = ImageInterface::THUMBNAIL_OUTBOUND; |
||
| 26 | if (!empty($options['mode']) && 'inset' === $options['mode']) { |
||
| 27 | $mode = ImageInterface::THUMBNAIL_INSET; |
||
| 28 | } |
||
| 29 | |||
| 30 | if (!empty($options['filter'])) { |
||
| 31 | $filter = \constant('Imagine\Image\ImageInterface::FILTER_'.mb_strtoupper($options['filter'])); |
||
| 32 | } |
||
| 33 | if (empty($filter)) { |
||
| 34 | $filter = ImageInterface::FILTER_UNDEFINED; |
||
| 35 | } |
||
| 36 | |||
| 37 | $width = isset($options['size'][0]) ? $options['size'][0] : null; |
||
| 38 | $height = isset($options['size'][1]) ? $options['size'][1] : null; |
||
| 39 | |||
| 40 | $size = $image->getSize(); |
||
| 41 | $origWidth = $size->getWidth(); |
||
| 42 | $origHeight = $size->getHeight(); |
||
| 43 | |||
| 44 | if (null === $width || null === $height) { |
||
| 45 | if (null === $height) { |
||
| 46 | $height = (int) (($width / $origWidth) * $origHeight); |
||
| 47 | } elseif (null === $width) { |
||
| 48 | $width = (int) (($height / $origHeight) * $origWidth); |
||
| 49 | } |
||
| 50 | } |
||
| 51 | |||
| 52 | if (($origWidth > $width || $origHeight > $height) |
||
| 53 | || (!empty($options['allow_upscale']) && ($origWidth !== $width || $origHeight !== $height)) |
||
| 54 | ) { |
||
| 55 | $filter = new Thumbnail(new Box($width, $height), $mode, $filter); |
||
| 56 | $image = $filter->apply($image); |
||
| 57 | } |
||
| 58 | |||
| 59 | return $image; |
||
| 60 | } |
||
| 61 | } |
||
| 62 |