| Conditions | 9 |
| Paths | 12 |
| Total Lines | 86 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 1 | 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 |
||
| 178 | protected function blockImage($Line) |
||
| 179 | { |
||
| 180 | if (1 !== preg_match($this->MarkdownImageRegex, $Line['text'])) { |
||
| 181 | return; |
||
| 182 | } |
||
| 183 | |||
| 184 | $InlineImage = $this->inlineImage($Line); |
||
| 185 | if (!isset($InlineImage)) { |
||
| 186 | return; |
||
| 187 | } |
||
| 188 | |||
| 189 | $block = $InlineImage; |
||
| 190 | |||
| 191 | /* |
||
| 192 | <figure> |
||
| 193 | <picture> |
||
| 194 | <source type="image/webp" |
||
| 195 | srcset="..." |
||
| 196 | sizes="..." |
||
| 197 | > |
||
| 198 | <img src="..." |
||
| 199 | srcset="..." |
||
| 200 | sizes="..." |
||
| 201 | > |
||
| 202 | </picture> |
||
| 203 | <figcaption>...</figcaption> |
||
| 204 | </figure> |
||
| 205 | */ |
||
| 206 | |||
| 207 | // creates a <picture> element with a <source> (WebP) and an <img> element |
||
| 208 | if (($this->builder->getConfig()->get('body.images.remote.enabled') ?? true) && ($this->builder->getConfig()->get('body.images.webp.enabled') ?? false) && !Image::isAnimatedGif($InlineImage['element']['attributes']['src'])) { |
||
| 209 | $assetWebp = Image::convertTopWebp($InlineImage['element']['attributes']['src'], $this->builder->getConfig()->get('assets.images.quality') ?? 75); |
||
| 210 | $srcset = ''; |
||
| 211 | if ($this->builder->getConfig()->get('body.images.responsive.enabled')) { |
||
| 212 | $srcset = Image::buildSrcset( |
||
| 213 | $assetWebp, |
||
| 214 | $this->builder->getConfig()->get('assets.images.responsive.widths') ?? [480, 640, 768, 1024, 1366, 1600, 1920] |
||
| 215 | ); |
||
| 216 | } |
||
| 217 | if (empty($srcset)) { |
||
| 218 | $srcset = (string) $assetWebp; |
||
| 219 | } |
||
| 220 | $PictureBlock = [ |
||
| 221 | 'element' => [ |
||
| 222 | 'name' => 'picture', |
||
| 223 | 'handler' => 'elements', |
||
| 224 | ], |
||
| 225 | ]; |
||
| 226 | $source = [ |
||
| 227 | 'element' => [ |
||
| 228 | 'name' => 'source', |
||
| 229 | 'attributes' => [ |
||
| 230 | 'type' => 'image/webp', |
||
| 231 | 'srcset' => $srcset, |
||
| 232 | 'sizes' => $this->builder->getConfig()->get('assets.images.responsive.sizes.default'), |
||
| 233 | ], |
||
| 234 | ], |
||
| 235 | ]; |
||
| 236 | $PictureBlock['element']['text'][] = $source['element']; |
||
| 237 | $PictureBlock['element']['text'][] = $InlineImage['element']; |
||
| 238 | $block = $PictureBlock; |
||
| 239 | } |
||
| 240 | |||
| 241 | // put <img> (or <picture>) in a <figure> element if there is a title (<figcaption>) |
||
| 242 | if (!empty($InlineImage['element']['attributes']['title'])) { |
||
| 243 | $FigureBlock = [ |
||
| 244 | 'element' => [ |
||
| 245 | 'name' => 'figure', |
||
| 246 | 'handler' => 'elements', |
||
| 247 | 'text' => [ |
||
| 248 | $block['element'], |
||
| 249 | ], |
||
| 250 | ], |
||
| 251 | ]; |
||
| 252 | $InlineFigcaption = [ |
||
| 253 | 'element' => [ |
||
| 254 | 'name' => 'figcaption', |
||
| 255 | 'text' => $InlineImage['element']['attributes']['title'], |
||
| 256 | ], |
||
| 257 | ]; |
||
| 258 | $FigureBlock['element']['text'][] = $InlineFigcaption['element']; |
||
| 259 | |||
| 260 | return $FigureBlock; |
||
| 261 | } |
||
| 262 | |||
| 263 | return $block; |
||
| 264 | } |
||
| 322 |