| Conditions | 19 |
| Paths | 74 |
| Total Lines | 50 |
| Code Lines | 25 |
| 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 |
||
| 118 | protected function setSizeOption(): void |
||
| 119 | { |
||
| 120 | // If no option has been provided, we'll use default values. |
||
| 121 | if ( |
||
| 122 | empty($this->userOptions[WebThumbnailer::MAX_HEIGHT]) |
||
| 123 | && empty($this->userOptions[WebThumbnailer::MAX_WIDTH]) |
||
| 124 | ) { |
||
| 125 | return; |
||
| 126 | } |
||
| 127 | |||
| 128 | // If the rules doesn't specify anything about size, abort. |
||
| 129 | if (empty($this->finderOptions[static::SIZE_KEY])) { |
||
| 130 | return; |
||
| 131 | } |
||
| 132 | |||
| 133 | // Load height user option. |
||
| 134 | if (!empty($this->userOptions[WebThumbnailer::MAX_HEIGHT])) { |
||
| 135 | $height = $this->userOptions[WebThumbnailer::MAX_HEIGHT]; |
||
| 136 | if (SizeUtils::isMetaSize((string) $height)) { |
||
| 137 | $height = SizeUtils::getMetaSize((string) $height); |
||
| 138 | } |
||
| 139 | } |
||
| 140 | |||
| 141 | // Load width user option. |
||
| 142 | if (!empty($this->userOptions[WebThumbnailer::MAX_WIDTH])) { |
||
| 143 | $width = $this->userOptions[WebThumbnailer::MAX_WIDTH]; |
||
| 144 | if (SizeUtils::isMetaSize((string) $width)) { |
||
| 145 | $width = SizeUtils::getMetaSize((string) $width); |
||
| 146 | } |
||
| 147 | } |
||
| 148 | |||
| 149 | // Trying to find a resolution higher than the one asked. |
||
| 150 | foreach ($this->finderOptions[static::SIZE_KEY] as $sizeOption => $value) { |
||
| 151 | if ($sizeOption == 'default') { |
||
| 152 | continue; |
||
| 153 | } |
||
| 154 | |||
| 155 | if ( |
||
| 156 | (empty($value['maxwidth']) || empty($width) || $value['maxwidth'] >= $width) |
||
| 157 | && (empty($value['maxheight']) || empty($height) || $value['maxheight'] >= $height) |
||
| 158 | ) { |
||
| 159 | $this->userOptions[static::SIZE_KEY] = $sizeOption; |
||
| 160 | break; |
||
| 161 | } |
||
| 162 | } |
||
| 163 | |||
| 164 | // If the resolution asked hasn't been reached, take the highest resolution we have. |
||
| 165 | if ((!empty($width) || !empty($height)) && empty($this->userOptions[static::SIZE_KEY])) { |
||
| 166 | $ref = array_keys($this->finderOptions[static::SIZE_KEY]); |
||
| 167 | $this->userOptions[static::SIZE_KEY] = end($ref); |
||
| 168 | } |
||
| 177 |