| Conditions | 14 |
| Paths | 64 |
| Total Lines | 37 |
| Code Lines | 22 |
| 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 |
||
| 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 | list($width, $height) = $options['size']; |
||
| 29 | |||
| 30 | $size = $image->getSize(); |
||
| 31 | $origWidth = $size->getWidth(); |
||
| 32 | $origHeight = $size->getHeight(); |
||
| 33 | |||
| 34 | if (null === $width || null === $height) { |
||
| 35 | if (null === $height) { |
||
| 36 | $height = (int) (($width / $origWidth) * $origHeight); |
||
| 37 | } elseif (null === $width) { |
||
| 38 | $width = (int) (($height / $origHeight) * $origWidth); |
||
| 39 | } |
||
| 40 | } |
||
| 41 | |||
| 42 | if (($origWidth > $width || $origHeight > $height) |
||
| 43 | || (!empty($options['allow_upscale']) && ($origWidth !== $width || $origHeight !== $height)) |
||
| 44 | ) { |
||
| 45 | $filter = new Thumbnail(new Box($width, $height), $mode, $filter); |
||
| 46 | $image = $filter->apply($image); |
||
| 47 | } |
||
| 48 | |||
| 49 | return $image; |
||
| 50 | } |
||
| 51 | } |
||
| 52 |