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