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