Conditions | 7 |
Paths | 6 |
Total Lines | 34 |
Code Lines | 19 |
Lines | 5 |
Ratio | 14.71 % |
Changes | 2 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
19 | public function load(ImageInterface $image, array $options = array()) |
||
20 | { |
||
21 | if (!isset($options['min'])) { |
||
22 | throw new \InvalidArgumentException('Missing min option.'); |
||
23 | } |
||
24 | |||
25 | list($width, $height) = $options['min']; |
||
26 | |||
27 | $size = $image->getSize(); |
||
28 | $origWidth = $size->getWidth(); |
||
29 | $origHeight = $size->getHeight(); |
||
30 | |||
31 | if ($origWidth < $width || $origHeight < $height) { |
||
32 | $widthRatio = $width / $origWidth; |
||
33 | $heightRatio = $height / $origHeight; |
||
34 | |||
35 | // faster check than is_null |
||
36 | View Code Duplication | if (null === $width || null === $height) { |
|
|
|||
37 | $ratio = max($widthRatio, $heightRatio); |
||
38 | } else { |
||
39 | $ratio = min($widthRatio, $heightRatio); |
||
40 | } |
||
41 | |||
42 | if ($ratio < 1) { |
||
43 | return $image; |
||
44 | } |
||
45 | |||
46 | $filter = new Resize(new Box(round($origWidth * $ratio), round($origHeight * $ratio))); |
||
47 | |||
48 | return $filter->apply($image); |
||
49 | } |
||
50 | |||
51 | return $image; |
||
52 | } |
||
53 | } |
||
54 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.