| Conditions | 14 |
| Paths | 9 |
| Total Lines | 38 |
| Code Lines | 24 |
| 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 |
||
| 162 | protected function applyOptions(array $attrs, array $options, array $globalOptions): array |
||
| 163 | { |
||
| 164 | $options = array_merge($globalOptions['attributes'] ?? [], $options); |
||
| 165 | $width = $options['width'] ?? null; |
||
| 166 | $height = $options['height'] ?? null; |
||
| 167 | |||
| 168 | // If embed output dimensions are set and numeric use them to calculate output with correct aspect ratio. |
||
| 169 | // If dimensions are not numeric attempt to set them based on manual input. |
||
| 170 | if (isset($attrs['width']) |
||
| 171 | && isset($attrs['height']) |
||
| 172 | && is_numeric($attrs['width']) |
||
| 173 | && is_numeric($attrs['height']) |
||
| 174 | ) { |
||
| 175 | $ratio = $attrs['width'] / $attrs['height']; |
||
| 176 | $attrs['width'] = $width ?: round(($height ?: $attrs['height']) * $ratio); |
||
| 177 | $attrs['height'] = $height ?: round($attrs['width'] / $ratio); |
||
| 178 | } elseif ($width || $height) { |
||
| 179 | $attrs['width'] = $width ?: $attrs['width']; |
||
| 180 | $attrs['height'] = $height ?: $attrs['height']; |
||
| 181 | } |
||
| 182 | |||
| 183 | $typeOptions = $this->getTypeOptions($globalOptions); |
||
| 184 | |||
| 185 | if ($options['autoplay'] ?? false) { |
||
| 186 | $attrs['autoplay'] = $options['autoplay']; |
||
| 187 | |||
| 188 | // We can remove autoplay option if type is "iframe" after we change "src" attribute. |
||
| 189 | if ($this->type === self::TYPE_IFRAME) { |
||
| 190 | $attrs['src'] = $this->addUrlParam($attrs['src'], sprintf('%s=%s', 'autoplay', $attrs['autoplay'])); |
||
| 191 | unset($options['autoplay']); |
||
| 192 | unset($attrs['autoplay']); |
||
| 193 | } |
||
| 194 | } |
||
| 195 | |||
| 196 | return array_filter( |
||
| 197 | array_merge($typeOptions, $options, $attrs), |
||
| 198 | function ($v) { |
||
| 199 | return $v !== null; |
||
| 200 | } |
||
| 213 |