Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like HtmlMin often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use HtmlMin, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
21 | class HtmlMin implements HtmlMinInterface |
||
22 | { |
||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | private static $regExSpace = "/[[:space:]]{2,}|[\r\n]/u"; |
||
27 | |||
28 | /** |
||
29 | * @var string[] |
||
30 | * |
||
31 | * @psalm-var list<string> |
||
32 | */ |
||
33 | private static $optional_end_tags = [ |
||
34 | 'html', |
||
35 | 'head', |
||
36 | 'body', |
||
37 | ]; |
||
38 | |||
39 | /** |
||
40 | * @var string[] |
||
41 | * |
||
42 | * @psalm-var list<string> |
||
43 | */ |
||
44 | private static $selfClosingTags = [ |
||
45 | 'area', |
||
46 | 'base', |
||
47 | 'basefont', |
||
48 | 'br', |
||
49 | 'col', |
||
50 | 'command', |
||
51 | 'embed', |
||
52 | 'frame', |
||
53 | 'hr', |
||
54 | 'img', |
||
55 | 'input', |
||
56 | 'isindex', |
||
57 | 'keygen', |
||
58 | 'link', |
||
59 | 'meta', |
||
60 | 'param', |
||
61 | 'source', |
||
62 | 'track', |
||
63 | 'wbr', |
||
64 | ]; |
||
65 | |||
66 | /** |
||
67 | * @var string[] |
||
68 | * |
||
69 | * @psalm-var array<string, string> |
||
70 | */ |
||
71 | private static $trimWhitespaceFromTags = [ |
||
72 | 'article' => '', |
||
73 | 'br' => '', |
||
74 | 'div' => '', |
||
75 | 'footer' => '', |
||
76 | 'hr' => '', |
||
77 | 'nav' => '', |
||
78 | 'p' => '', |
||
79 | 'script' => '', |
||
80 | ]; |
||
81 | |||
82 | /** |
||
83 | * @var array |
||
84 | */ |
||
85 | private static $booleanAttributes = [ |
||
86 | 'allowfullscreen' => '', |
||
87 | 'async' => '', |
||
88 | 'autofocus' => '', |
||
89 | 'autoplay' => '', |
||
90 | 'checked' => '', |
||
91 | 'compact' => '', |
||
92 | 'controls' => '', |
||
93 | 'declare' => '', |
||
94 | 'default' => '', |
||
95 | 'defaultchecked' => '', |
||
96 | 'defaultmuted' => '', |
||
97 | 'defaultselected' => '', |
||
98 | 'defer' => '', |
||
99 | 'disabled' => '', |
||
100 | 'enabled' => '', |
||
101 | 'formnovalidate' => '', |
||
102 | 'hidden' => '', |
||
103 | 'indeterminate' => '', |
||
104 | 'inert' => '', |
||
105 | 'ismap' => '', |
||
106 | 'itemscope' => '', |
||
107 | 'loop' => '', |
||
108 | 'multiple' => '', |
||
109 | 'muted' => '', |
||
110 | 'nohref' => '', |
||
111 | 'noresize' => '', |
||
112 | 'noshade' => '', |
||
113 | 'novalidate' => '', |
||
114 | 'nowrap' => '', |
||
115 | 'open' => '', |
||
116 | 'pauseonexit' => '', |
||
117 | 'readonly' => '', |
||
118 | 'required' => '', |
||
119 | 'reversed' => '', |
||
120 | 'scoped' => '', |
||
121 | 'seamless' => '', |
||
122 | 'selected' => '', |
||
123 | 'sortable' => '', |
||
124 | 'truespeed' => '', |
||
125 | 'typemustmatch' => '', |
||
126 | 'visible' => '', |
||
127 | ]; |
||
128 | |||
129 | /** |
||
130 | * @var array |
||
131 | */ |
||
132 | private static $skipTagsForRemoveWhitespace = [ |
||
133 | 'code', |
||
134 | 'pre', |
||
135 | 'script', |
||
136 | 'style', |
||
137 | 'textarea', |
||
138 | ]; |
||
139 | |||
140 | /** |
||
141 | * @var array |
||
142 | */ |
||
143 | private $protectedChildNodes = []; |
||
144 | |||
145 | /** |
||
146 | * @var string |
||
147 | */ |
||
148 | private $protectedChildNodesHelper = 'html-min--voku--saved-content'; |
||
149 | |||
150 | /** |
||
151 | * @var bool |
||
152 | */ |
||
153 | private $doOptimizeViaHtmlDomParser = true; |
||
154 | |||
155 | /** |
||
156 | * @var bool |
||
157 | */ |
||
158 | private $doOptimizeAttributes = true; |
||
159 | |||
160 | /** |
||
161 | * @var bool |
||
162 | */ |
||
163 | private $doRemoveComments = true; |
||
164 | |||
165 | /** |
||
166 | * @var bool |
||
167 | */ |
||
168 | private $doRemoveWhitespaceAroundTags = false; |
||
169 | |||
170 | /** |
||
171 | * @var bool |
||
172 | */ |
||
173 | private $doRemoveOmittedQuotes = true; |
||
174 | |||
175 | /** |
||
176 | * @var bool |
||
177 | */ |
||
178 | private $doRemoveOmittedHtmlTags = true; |
||
179 | |||
180 | /** |
||
181 | * @var bool |
||
182 | */ |
||
183 | private $doRemoveHttpPrefixFromAttributes = false; |
||
184 | |||
185 | /** |
||
186 | * @var bool |
||
187 | */ |
||
188 | private $doRemoveHttpsPrefixFromAttributes = false; |
||
189 | |||
190 | /** |
||
191 | * @var bool |
||
192 | */ |
||
193 | private $doKeepHttpAndHttpsPrefixOnExternalAttributes = false; |
||
194 | |||
195 | /** |
||
196 | * @var bool |
||
197 | */ |
||
198 | private $doMakeSameDomainsLinksRelative = false; |
||
199 | |||
200 | /** |
||
201 | * @var string[] |
||
202 | */ |
||
203 | private $localDomains = []; |
||
204 | |||
205 | /** |
||
206 | * @var string[] |
||
207 | */ |
||
208 | private $domainsToRemoveHttpPrefixFromAttributes = [ |
||
209 | 'google.com', |
||
210 | 'google.de', |
||
211 | ]; |
||
212 | |||
213 | /** |
||
214 | * @var string[] |
||
215 | */ |
||
216 | private $specialHtmlCommentsStaringWith = []; |
||
217 | |||
218 | /** |
||
219 | * @var string[] |
||
220 | */ |
||
221 | private $specialHtmlCommentsEndingWith = []; |
||
222 | |||
223 | /** |
||
224 | * @var bool |
||
225 | */ |
||
226 | private $doSortCssClassNames = true; |
||
227 | |||
228 | /** |
||
229 | * @var bool |
||
230 | */ |
||
231 | private $doSortHtmlAttributes = true; |
||
232 | |||
233 | /** |
||
234 | * @var bool |
||
235 | */ |
||
236 | private $doRemoveDeprecatedScriptCharsetAttribute = true; |
||
237 | |||
238 | /** |
||
239 | * @var bool |
||
240 | */ |
||
241 | private $doRemoveDefaultAttributes = false; |
||
242 | |||
243 | /** |
||
244 | * @var bool |
||
245 | */ |
||
246 | private $doRemoveDeprecatedAnchorName = true; |
||
247 | |||
248 | /** |
||
249 | * @var bool |
||
250 | */ |
||
251 | private $doRemoveDeprecatedTypeFromStylesheetLink = true; |
||
252 | |||
253 | /** |
||
254 | * @var bool |
||
255 | */ |
||
256 | private $doRemoveDeprecatedTypeFromStyleAndLinkTag = true; |
||
257 | |||
258 | /** |
||
259 | * @var bool |
||
260 | */ |
||
261 | private $doRemoveDefaultMediaTypeFromStyleAndLinkTag = true; |
||
262 | |||
263 | /** |
||
264 | * @var bool |
||
265 | */ |
||
266 | private $doRemoveDefaultTypeFromButton = false; |
||
267 | |||
268 | /** |
||
269 | * @var bool |
||
270 | */ |
||
271 | private $doRemoveDeprecatedTypeFromScriptTag = true; |
||
272 | |||
273 | /** |
||
274 | * @var bool |
||
275 | */ |
||
276 | private $doRemoveValueFromEmptyInput = true; |
||
277 | |||
278 | /** |
||
279 | * @var bool |
||
280 | */ |
||
281 | private $doRemoveEmptyAttributes = true; |
||
282 | |||
283 | /** |
||
284 | * @var bool |
||
285 | */ |
||
286 | private $doSumUpWhitespace = true; |
||
287 | |||
288 | /** |
||
289 | * @var bool |
||
290 | */ |
||
291 | private $doRemoveSpacesBetweenTags = false; |
||
292 | |||
293 | /** |
||
294 | * @var bool |
||
295 | */ |
||
296 | private $keepBrokenHtml = false; |
||
297 | |||
298 | /** |
||
299 | * @var bool |
||
300 | */ |
||
301 | private $withDocType = false; |
||
302 | |||
303 | /** |
||
304 | * @var HtmlMinDomObserverInterface[]|\SplObjectStorage |
||
305 | * |
||
306 | * @psalm-var \SplObjectStorage<HtmlMinDomObserverInterface> |
||
307 | */ |
||
308 | private $domLoopObservers; |
||
309 | |||
310 | /** |
||
311 | * @var int |
||
312 | */ |
||
313 | private $protected_tags_counter = 0; |
||
314 | |||
315 | /** |
||
316 | * @var bool |
||
317 | */ |
||
318 | private $isHTML4 = false; |
||
319 | |||
320 | /** |
||
321 | * @var bool |
||
322 | */ |
||
323 | private $isXHTML = false; |
||
324 | |||
325 | /** |
||
326 | * @var string[]|null |
||
327 | */ |
||
328 | private $templateLogicSyntaxInSpecialScriptTags; |
||
329 | |||
330 | /** |
||
331 | * HtmlMin constructor. |
||
332 | */ |
||
333 | 61 | public function __construct() |
|
339 | |||
340 | /** |
||
341 | * @param HtmlMinDomObserverInterface $observer |
||
342 | * |
||
343 | * @return void |
||
344 | */ |
||
345 | 61 | public function attachObserverToTheDomLoop(HtmlMinDomObserverInterface $observer) |
|
349 | |||
350 | /** |
||
351 | * @param bool $doOptimizeAttributes |
||
352 | * |
||
353 | * @return $this |
||
354 | */ |
||
355 | 2 | public function doOptimizeAttributes(bool $doOptimizeAttributes = true): self |
|
361 | |||
362 | /** |
||
363 | * @param bool $doOptimizeViaHtmlDomParser |
||
364 | * |
||
365 | * @return $this |
||
366 | */ |
||
367 | 2 | public function doOptimizeViaHtmlDomParser(bool $doOptimizeViaHtmlDomParser = true): self |
|
373 | |||
374 | /** |
||
375 | * @param bool $doRemoveComments |
||
376 | * |
||
377 | * @return $this |
||
378 | */ |
||
379 | 3 | public function doRemoveComments(bool $doRemoveComments = true): self |
|
385 | |||
386 | /** |
||
387 | * @param bool $doRemoveDefaultAttributes |
||
388 | * |
||
389 | * @return $this |
||
390 | */ |
||
391 | 2 | public function doRemoveDefaultAttributes(bool $doRemoveDefaultAttributes = true): self |
|
397 | |||
398 | /** |
||
399 | * @param bool $doRemoveDeprecatedAnchorName |
||
400 | * |
||
401 | * @return $this |
||
402 | */ |
||
403 | 2 | public function doRemoveDeprecatedAnchorName(bool $doRemoveDeprecatedAnchorName = true): self |
|
409 | |||
410 | /** |
||
411 | * @param bool $doRemoveDeprecatedScriptCharsetAttribute |
||
412 | * |
||
413 | * @return $this |
||
414 | */ |
||
415 | 2 | public function doRemoveDeprecatedScriptCharsetAttribute(bool $doRemoveDeprecatedScriptCharsetAttribute = true): self |
|
421 | |||
422 | /** |
||
423 | * @param bool $doRemoveDeprecatedTypeFromScriptTag |
||
424 | * |
||
425 | * @return $this |
||
426 | */ |
||
427 | 3 | public function doRemoveDeprecatedTypeFromScriptTag(bool $doRemoveDeprecatedTypeFromScriptTag = true): self |
|
433 | |||
434 | /** |
||
435 | * @param bool $doRemoveDeprecatedTypeFromStylesheetLink |
||
436 | * |
||
437 | * @return $this |
||
438 | */ |
||
439 | 2 | public function doRemoveDeprecatedTypeFromStylesheetLink(bool $doRemoveDeprecatedTypeFromStylesheetLink = true): self |
|
445 | |||
446 | /** |
||
447 | * @param bool $doRemoveDeprecatedTypeFromStyleAndLinkTag |
||
448 | * |
||
449 | * @return $this |
||
450 | */ |
||
451 | 1 | public function doRemoveDeprecatedTypeFromStyleAndLinkTag(bool $doRemoveDeprecatedTypeFromStyleAndLinkTag = true): self |
|
457 | |||
458 | /** |
||
459 | * @param bool $doRemoveDefaultMediaTypeFromStyleAndLinkTag |
||
460 | * |
||
461 | * @return $this |
||
462 | */ |
||
463 | 1 | public function doRemoveDefaultMediaTypeFromStyleAndLinkTag(bool $doRemoveDefaultMediaTypeFromStyleAndLinkTag = true): self |
|
469 | |||
470 | /** |
||
471 | * @param bool $doRemoveDefaultTypeFromButton |
||
472 | * |
||
473 | * @return $this |
||
474 | */ |
||
475 | 1 | public function doRemoveDefaultTypeFromButton(bool $doRemoveDefaultTypeFromButton = true): self |
|
481 | |||
482 | /** |
||
483 | * @param bool $doRemoveEmptyAttributes |
||
484 | * |
||
485 | * @return $this |
||
486 | */ |
||
487 | 2 | public function doRemoveEmptyAttributes(bool $doRemoveEmptyAttributes = true): self |
|
493 | |||
494 | /** |
||
495 | * @param bool $doRemoveHttpPrefixFromAttributes |
||
496 | * |
||
497 | * @return $this |
||
498 | */ |
||
499 | 6 | public function doRemoveHttpPrefixFromAttributes(bool $doRemoveHttpPrefixFromAttributes = true): self |
|
505 | |||
506 | /** |
||
507 | * @param bool $doRemoveHttpsPrefixFromAttributes |
||
508 | * |
||
509 | * @return $this |
||
510 | */ |
||
511 | 1 | public function doRemoveHttpsPrefixFromAttributes(bool $doRemoveHttpsPrefixFromAttributes = true): self |
|
517 | |||
518 | /** |
||
519 | * @param bool $doKeepHttpAndHttpsPrefixOnExternalAttributes |
||
520 | * |
||
521 | * @return $this |
||
522 | */ |
||
523 | 1 | public function doKeepHttpAndHttpsPrefixOnExternalAttributes(bool $doKeepHttpAndHttpsPrefixOnExternalAttributes = true): self |
|
529 | |||
530 | /** |
||
531 | * @param string[] $localDomains |
||
532 | * |
||
533 | * @return $this |
||
534 | */ |
||
535 | 1 | public function doMakeSameDomainsLinksRelative(array $localDomains): self |
|
547 | |||
548 | /** |
||
549 | * @return string[] |
||
550 | */ |
||
551 | 1 | public function getLocalDomains(): array |
|
555 | |||
556 | /** |
||
557 | * @param bool $doRemoveOmittedHtmlTags |
||
558 | * |
||
559 | * @return $this |
||
560 | */ |
||
561 | 1 | public function doRemoveOmittedHtmlTags(bool $doRemoveOmittedHtmlTags = true): self |
|
567 | |||
568 | /** |
||
569 | * @param bool $doRemoveOmittedQuotes |
||
570 | * |
||
571 | * @return $this |
||
572 | */ |
||
573 | 1 | public function doRemoveOmittedQuotes(bool $doRemoveOmittedQuotes = true): self |
|
579 | |||
580 | /** |
||
581 | * @param bool $doRemoveSpacesBetweenTags |
||
582 | * |
||
583 | * @return $this |
||
584 | */ |
||
585 | 1 | public function doRemoveSpacesBetweenTags(bool $doRemoveSpacesBetweenTags = true): self |
|
591 | |||
592 | /** |
||
593 | * @param bool $doRemoveValueFromEmptyInput |
||
594 | * |
||
595 | * @return $this |
||
596 | */ |
||
597 | 2 | public function doRemoveValueFromEmptyInput(bool $doRemoveValueFromEmptyInput = true): self |
|
603 | |||
604 | /** |
||
605 | * @param bool $doRemoveWhitespaceAroundTags |
||
606 | * |
||
607 | * @return $this |
||
608 | */ |
||
609 | 5 | public function doRemoveWhitespaceAroundTags(bool $doRemoveWhitespaceAroundTags = true): self |
|
615 | |||
616 | /** |
||
617 | * @param bool $doSortCssClassNames |
||
618 | * |
||
619 | * @return $this |
||
620 | */ |
||
621 | 2 | public function doSortCssClassNames(bool $doSortCssClassNames = true): self |
|
627 | |||
628 | /** |
||
629 | * @param bool $doSortHtmlAttributes |
||
630 | * |
||
631 | * @return $this |
||
632 | */ |
||
633 | 2 | public function doSortHtmlAttributes(bool $doSortHtmlAttributes = true): self |
|
639 | |||
640 | /** |
||
641 | * @param bool $doSumUpWhitespace |
||
642 | * |
||
643 | * @return $this |
||
644 | */ |
||
645 | 2 | public function doSumUpWhitespace(bool $doSumUpWhitespace = true): self |
|
651 | |||
652 | 57 | private function domNodeAttributesToString(\DOMNode $node): string |
|
713 | |||
714 | /** |
||
715 | * @param \DOMNode $node |
||
716 | * |
||
717 | * @return bool |
||
718 | */ |
||
719 | 56 | private function domNodeClosingTagOptional(\DOMNode $node): bool |
|
983 | |||
984 | 57 | protected function domNodeToString(\DOMNode $node): string |
|
1083 | |||
1084 | /** |
||
1085 | * @param \DOMNode $node |
||
1086 | * |
||
1087 | * @return string |
||
1088 | */ |
||
1089 | 57 | private function getDoctype(\DOMNode $node): string |
|
1119 | |||
1120 | /** |
||
1121 | * @return array |
||
1122 | */ |
||
1123 | public function getDomainsToRemoveHttpPrefixFromAttributes(): array |
||
1127 | |||
1128 | /** |
||
1129 | * @return bool |
||
1130 | */ |
||
1131 | public function isDoOptimizeAttributes(): bool |
||
1135 | |||
1136 | /** |
||
1137 | * @return bool |
||
1138 | */ |
||
1139 | public function isDoOptimizeViaHtmlDomParser(): bool |
||
1143 | |||
1144 | /** |
||
1145 | * @return bool |
||
1146 | */ |
||
1147 | public function isDoRemoveComments(): bool |
||
1151 | |||
1152 | /** |
||
1153 | * @return bool |
||
1154 | */ |
||
1155 | 38 | public function isDoRemoveDefaultAttributes(): bool |
|
1159 | |||
1160 | /** |
||
1161 | * @return bool |
||
1162 | */ |
||
1163 | 38 | public function isDoRemoveDeprecatedAnchorName(): bool |
|
1167 | |||
1168 | /** |
||
1169 | * @return bool |
||
1170 | */ |
||
1171 | 38 | public function isDoRemoveDeprecatedScriptCharsetAttribute(): bool |
|
1175 | |||
1176 | /** |
||
1177 | * @return bool |
||
1178 | */ |
||
1179 | 38 | public function isDoRemoveDeprecatedTypeFromScriptTag(): bool |
|
1183 | |||
1184 | /** |
||
1185 | * @return bool |
||
1186 | */ |
||
1187 | 38 | public function isDoRemoveDeprecatedTypeFromStylesheetLink(): bool |
|
1191 | |||
1192 | /** |
||
1193 | * @return bool |
||
1194 | */ |
||
1195 | 38 | public function isDoRemoveDeprecatedTypeFromStyleAndLinkTag(): bool |
|
1199 | |||
1200 | /** |
||
1201 | * @return bool |
||
1202 | */ |
||
1203 | 38 | public function isDoRemoveDefaultMediaTypeFromStyleAndLinkTag(): bool |
|
1207 | |||
1208 | /** |
||
1209 | * @return bool |
||
1210 | */ |
||
1211 | 37 | public function isDoRemoveDefaultTypeFromButton(): bool |
|
1215 | |||
1216 | /** |
||
1217 | * @return bool |
||
1218 | */ |
||
1219 | 37 | public function isDoRemoveEmptyAttributes(): bool |
|
1223 | |||
1224 | /** |
||
1225 | * @return bool |
||
1226 | */ |
||
1227 | 38 | public function isDoRemoveHttpPrefixFromAttributes(): bool |
|
1231 | |||
1232 | /** |
||
1233 | * @return bool |
||
1234 | */ |
||
1235 | 38 | public function isDoRemoveHttpsPrefixFromAttributes(): bool |
|
1239 | |||
1240 | /** |
||
1241 | * @return bool |
||
1242 | */ |
||
1243 | 4 | public function isdoKeepHttpAndHttpsPrefixOnExternalAttributes(): bool |
|
1247 | |||
1248 | /** |
||
1249 | * @return bool |
||
1250 | */ |
||
1251 | 38 | public function isDoMakeSameDomainsLinksRelative(): bool |
|
1255 | |||
1256 | /** |
||
1257 | * @return bool |
||
1258 | */ |
||
1259 | public function isDoRemoveOmittedHtmlTags(): bool |
||
1263 | |||
1264 | /** |
||
1265 | * @return bool |
||
1266 | */ |
||
1267 | public function isDoRemoveOmittedQuotes(): bool |
||
1271 | |||
1272 | /** |
||
1273 | * @return bool |
||
1274 | */ |
||
1275 | public function isDoRemoveSpacesBetweenTags(): bool |
||
1279 | |||
1280 | /** |
||
1281 | * @return bool |
||
1282 | */ |
||
1283 | 37 | public function isDoRemoveValueFromEmptyInput(): bool |
|
1287 | |||
1288 | /** |
||
1289 | * @return bool |
||
1290 | */ |
||
1291 | public function isDoRemoveWhitespaceAroundTags(): bool |
||
1295 | |||
1296 | /** |
||
1297 | * @return bool |
||
1298 | */ |
||
1299 | 37 | public function isDoSortCssClassNames(): bool |
|
1303 | |||
1304 | /** |
||
1305 | * @return bool |
||
1306 | */ |
||
1307 | 38 | public function isDoSortHtmlAttributes(): bool |
|
1311 | |||
1312 | /** |
||
1313 | * @return bool |
||
1314 | */ |
||
1315 | public function isDoSumUpWhitespace(): bool |
||
1319 | |||
1320 | /** |
||
1321 | * @return bool |
||
1322 | */ |
||
1323 | 5 | public function isHTML4(): bool |
|
1327 | |||
1328 | /** |
||
1329 | * @return bool |
||
1330 | */ |
||
1331 | 5 | public function isXHTML(): bool |
|
1335 | |||
1336 | /** |
||
1337 | * @param string $html |
||
1338 | * @param bool $multiDecodeNewHtmlEntity |
||
1339 | * |
||
1340 | * @return string |
||
1341 | */ |
||
1342 | 61 | public function minify($html, $multiDecodeNewHtmlEntity = false): string |
|
1467 | |||
1468 | /** |
||
1469 | * @param \DOMNode $node |
||
1470 | * |
||
1471 | * @return \DOMNode|null |
||
1472 | */ |
||
1473 | 56 | protected function getNextSiblingOfTypeDOMElement(\DOMNode $node) |
|
1496 | |||
1497 | /** |
||
1498 | * Check if the current string is an conditional comment. |
||
1499 | * |
||
1500 | * INFO: since IE >= 10 conditional comment are not working anymore |
||
1501 | * |
||
1502 | * <!--[if expression]> HTML <![endif]--> |
||
1503 | * <![if expression]> HTML <![endif]> |
||
1504 | * |
||
1505 | * @param string $comment |
||
1506 | * |
||
1507 | * @return bool |
||
1508 | */ |
||
1509 | 5 | private function isConditionalComment($comment): bool |
|
1529 | |||
1530 | /** |
||
1531 | * Check if the current string is an special comment. |
||
1532 | * |
||
1533 | * @param string $comment |
||
1534 | * |
||
1535 | * @return bool |
||
1536 | */ |
||
1537 | 5 | private function isSpecialComment($comment): bool |
|
1553 | |||
1554 | /** |
||
1555 | * @param string $html |
||
1556 | * @param bool $multiDecodeNewHtmlEntity |
||
1557 | * |
||
1558 | * @return string |
||
1559 | */ |
||
1560 | 57 | private function minifyHtmlDom($html, $multiDecodeNewHtmlEntity): string |
|
1648 | |||
1649 | /** |
||
1650 | * @param SimpleHtmlDomInterface $domElement |
||
1651 | * |
||
1652 | * @return void |
||
1653 | */ |
||
1654 | 57 | private function notifyObserversAboutDomElementAfterMinification(SimpleHtmlDomInterface $domElement) |
|
1660 | |||
1661 | /** |
||
1662 | * @param SimpleHtmlDomInterface $domElement |
||
1663 | * |
||
1664 | * @return void |
||
1665 | */ |
||
1666 | 57 | private function notifyObserversAboutDomElementBeforeMinification(SimpleHtmlDomInterface $domElement) |
|
1672 | |||
1673 | /** |
||
1674 | * @param HtmlDomParser $dom |
||
1675 | * @param string $selector |
||
1676 | * |
||
1677 | * @return HtmlDomParser |
||
1678 | */ |
||
1679 | 57 | private function protectTagHelper(HtmlDomParser $dom, string $selector): HtmlDomParser |
|
1697 | |||
1698 | /** |
||
1699 | * Prevent changes of inline "styles" and "scripts". |
||
1700 | * |
||
1701 | * @param HtmlDomParser $dom |
||
1702 | * |
||
1703 | * @return HtmlDomParser |
||
1704 | */ |
||
1705 | 57 | private function protectTags(HtmlDomParser $dom): HtmlDomParser |
|
1758 | |||
1759 | /** |
||
1760 | * Remove comments in the dom. |
||
1761 | * |
||
1762 | * @param HtmlDomParser $dom |
||
1763 | * |
||
1764 | * @return HtmlDomParser |
||
1765 | */ |
||
1766 | 55 | private function removeComments(HtmlDomParser $dom): HtmlDomParser |
|
1783 | |||
1784 | /** |
||
1785 | * Trim tags in the dom. |
||
1786 | * |
||
1787 | * @param SimpleHtmlDomInterface $element |
||
1788 | * |
||
1789 | * @return void |
||
1790 | */ |
||
1791 | 3 | private function removeWhitespaceAroundTags(SimpleHtmlDomInterface $element) |
|
1820 | |||
1821 | /** |
||
1822 | * Callback function for preg_replace_callback use. |
||
1823 | * |
||
1824 | * @param array $matches PREG matches |
||
1825 | * |
||
1826 | * @return string |
||
1827 | */ |
||
1828 | 13 | private function restoreProtectedHtml($matches): string |
|
1834 | |||
1835 | /** |
||
1836 | * @param string[] $domainsToRemoveHttpPrefixFromAttributes |
||
1837 | * |
||
1838 | * @return $this |
||
1839 | */ |
||
1840 | 2 | public function setDomainsToRemoveHttpPrefixFromAttributes($domainsToRemoveHttpPrefixFromAttributes): self |
|
1846 | |||
1847 | /** |
||
1848 | * @param string[] $startingWith |
||
1849 | * @param string[] $endingWith |
||
1850 | * |
||
1851 | * @return $this |
||
1852 | */ |
||
1853 | 1 | public function setSpecialHtmlComments(array $startingWith, array $endingWith = []): self |
|
1860 | |||
1861 | /** |
||
1862 | * Sum-up extra whitespace from dom-nodes. |
||
1863 | * |
||
1864 | * @param HtmlDomParser $dom |
||
1865 | * |
||
1866 | * @return HtmlDomParser |
||
1867 | */ |
||
1868 | 56 | private function sumUpWhitespace(HtmlDomParser $dom): HtmlDomParser |
|
1901 | |||
1902 | /** |
||
1903 | * WARNING: maybe bad for performance ... |
||
1904 | * |
||
1905 | * @param bool $keepBrokenHtml |
||
1906 | * |
||
1907 | * @return HtmlMin |
||
1908 | */ |
||
1909 | 2 | public function useKeepBrokenHtml(bool $keepBrokenHtml): self |
|
1915 | |||
1916 | /** |
||
1917 | * @param string[] $templateLogicSyntaxInSpecialScriptTags |
||
1918 | * |
||
1919 | * @return HtmlMin |
||
1920 | */ |
||
1921 | 1 | public function overwriteTemplateLogicSyntaxInSpecialScriptTags(array $templateLogicSyntaxInSpecialScriptTags): self |
|
1933 | } |
||
1934 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.