| Conditions | 10 |
| Paths | 1 |
| Total Lines | 27 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 2 |
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 |
||
| 70 | protected function doLazyload(string $html): string |
||
| 71 | { |
||
| 72 | return \preg_replace_callback('/<(img|source|video)([^>]+)>/m', function ($match) { |
||
| 73 | list($all, $tag, $props) = $match; |
||
| 74 | |||
| 75 | if (empty(\trim($props, ' /')) || \strpos($props, "no-{$this->lazyClass}") !== false) { |
||
| 76 | return $all; |
||
| 77 | } |
||
| 78 | |||
| 79 | if (\stripos($props, 'data-src') !== false || \stripos($props, 'data-poster') !== false) { |
||
| 80 | return $all; |
||
| 81 | } |
||
| 82 | |||
| 83 | // For source no need src, for video no need src if not already there! |
||
| 84 | $needSrc = $tag !== 'source' && ($tag !== 'video' || \stripos($props, 'src') !== false); |
||
| 85 | |||
| 86 | if (\stripos($props, ' class') === false) { |
||
| 87 | $tag .= " class=\"{$this->lazyClass} yall\""; |
||
| 88 | } |
||
| 89 | if (\stripos($props, ' poster') !== false) { |
||
| 90 | $tag .= " poster=\"{$this->placeholder}\""; |
||
| 91 | } |
||
| 92 | |||
| 93 | $src = $needSrc ? " src=\"{$this->placeholder}\"" : ''; |
||
| 94 | |||
| 95 | return "<$tag$src" . $this->doReplacements($props) . '>'; |
||
| 96 | }, $html); |
||
| 97 | } |
||
| 137 |