| Conditions | 6 |
| Paths | 8 |
| Total Lines | 85 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 144 | protected function blockImage($Line) |
||
| 145 | { |
||
| 146 | if (1 !== preg_match($this->MarkdownImageRegex, $Line['text'])) { |
||
| 147 | return; |
||
| 148 | } |
||
| 149 | |||
| 150 | $InlineImage = $this->inlineImage($Line); |
||
| 151 | if (!isset($InlineImage)) { |
||
| 152 | return; |
||
| 153 | } |
||
| 154 | |||
| 155 | $block = $InlineImage; |
||
| 156 | |||
| 157 | /* |
||
| 158 | <figure> |
||
| 159 | <picture> |
||
| 160 | <source type="image/webp" |
||
| 161 | srcset="..." |
||
| 162 | sizes="..." |
||
| 163 | > |
||
| 164 | <img src="..." |
||
| 165 | srcset="..." |
||
| 166 | sizes="..." |
||
| 167 | > |
||
| 168 | </picture> |
||
| 169 | <figcaption>...</figcaption> |
||
| 170 | </figure> |
||
| 171 | */ |
||
| 172 | |||
| 173 | // creates a <picture> element with <source> and <img> elements |
||
| 174 | if ($this->builder->getConfig()->get('body.images.webp.enabled') ?? false) { |
||
| 175 | $assetWebp = Image::convertTopWebp($InlineImage['element']['attributes']['src'], $this->builder->getConfig()->get('assets.images.quality') ?? 85); |
||
| 176 | $srcset = Image::getSrcset( |
||
| 177 | $assetWebp, |
||
| 178 | $this->builder->getConfig()->get('assets.images.responsive.width.steps') ?? 5, |
||
| 179 | $this->builder->getConfig()->get('assets.images.responsive.width.min') ?? 320, |
||
| 180 | $this->builder->getConfig()->get('assets.images.responsive.width.max') ?? 1280 |
||
| 181 | ); |
||
| 182 | if (empty($srcset)) { |
||
| 183 | $srcset = (string) $assetWebp; |
||
| 184 | } |
||
| 185 | $PictureBlock = [ |
||
| 186 | 'element' => [ |
||
| 187 | 'name' => 'picture', |
||
| 188 | 'handler' => 'elements', |
||
| 189 | ], |
||
| 190 | ]; |
||
| 191 | $source = [ |
||
| 192 | 'element' => [ |
||
| 193 | 'name' => 'source', |
||
| 194 | 'attributes' => [ |
||
| 195 | 'type' => 'image/webp', |
||
| 196 | 'srcset' => $srcset, |
||
| 197 | 'sizes' => $this->builder->getConfig()->get('assets.images.responsive.sizes.default'), |
||
| 198 | ], |
||
| 199 | ], |
||
| 200 | ]; |
||
| 201 | $PictureBlock['element']['text'][] = $source['element']; |
||
| 202 | $PictureBlock['element']['text'][] = $InlineImage['element']; |
||
| 203 | $block = $PictureBlock; |
||
| 204 | } |
||
| 205 | |||
| 206 | // put <img> or <picture> in a <figure> element if there is a title |
||
| 207 | if (!empty($InlineImage['element']['attributes']['title'])) { |
||
| 208 | $FigureBlock = [ |
||
| 209 | 'element' => [ |
||
| 210 | 'name' => 'figure', |
||
| 211 | 'handler' => 'elements', |
||
| 212 | 'text' => [ |
||
| 213 | $block['element'], |
||
| 214 | ], |
||
| 215 | ], |
||
| 216 | ]; |
||
| 217 | $InlineFigcaption = [ |
||
| 218 | 'element' => [ |
||
| 219 | 'name' => 'figcaption', |
||
| 220 | 'text' => $InlineImage['element']['attributes']['title'], |
||
| 221 | ], |
||
| 222 | ]; |
||
| 223 | $FigureBlock['element']['text'][] = $InlineFigcaption['element']; |
||
| 224 | |||
| 225 | return $FigureBlock; |
||
| 226 | } |
||
| 227 | |||
| 228 | return $block; |
||
| 229 | } |
||
| 239 |