Conditions | 12 |
Paths | 31 |
Total Lines | 36 |
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 |
||
50 | public function load(ImageInterface $image, array $options = []) |
||
51 | { |
||
52 | if (!isset($options[$this->dimensionKey]) && !isset($options[$this->ratioKey])) { |
||
53 | throw new \InvalidArgumentException("Missing $this->dimensionKey or $this->ratioKey option."); |
||
54 | } |
||
55 | |||
56 | $size = $image->getSize(); |
||
57 | $origWidth = $size->getWidth(); |
||
58 | $origHeight = $size->getHeight(); |
||
59 | $ratio = 1; |
||
60 | |||
61 | if (isset($options[$this->ratioKey])) { |
||
62 | $ratio = $this->absoluteRatio ? $options[$this->ratioKey] : $this->calcAbsoluteRatio($options[$this->ratioKey]); |
||
63 | } elseif (isset($options[$this->dimensionKey])) { |
||
64 | $size = $options[$this->dimensionKey]; |
||
65 | $width = isset($size[0]) ? $size[0] : null; |
||
66 | $height = isset($size[1]) ? $size[1] : null; |
||
67 | |||
68 | $widthRatio = $width / $origWidth; |
||
69 | $heightRatio = $height / $origHeight; |
||
70 | |||
71 | if (null === $width || null === $height) { |
||
72 | $ratio = max($widthRatio, $heightRatio); |
||
73 | } else { |
||
74 | $ratio = ('min' === $this->dimensionKey) ? max($widthRatio, $heightRatio) : min($widthRatio, $heightRatio); |
||
75 | } |
||
76 | } |
||
77 | |||
78 | if ($this->isImageProcessable($ratio)) { |
||
79 | $filter = new Resize(new Box(round($origWidth * $ratio), round($origHeight * $ratio))); |
||
80 | |||
81 | return $filter->apply($image); |
||
82 | } |
||
83 | |||
84 | return $image; |
||
85 | } |
||
86 | |||
97 |