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 $keepPrefixOnExternalAttributes = false; |
||
| 194 | |||
| 195 | /** |
||
| 196 | * @var bool |
||
| 197 | */ |
||
| 198 | private $doMakeSameDomainLinksRelative = false; |
||
| 199 | |||
| 200 | /** |
||
| 201 | * @var string |
||
| 202 | */ |
||
| 203 | private $localDomain = ''; |
||
| 204 | |||
| 205 | /** |
||
| 206 | * @var array |
||
| 207 | */ |
||
| 208 | private $domainsToRemoveHttpPrefixFromAttributes = [ |
||
| 209 | 'google.com', |
||
| 210 | 'google.de', |
||
| 211 | ]; |
||
| 212 | |||
| 213 | /** |
||
| 214 | * @var bool |
||
| 215 | */ |
||
| 216 | private $doSortCssClassNames = true; |
||
| 217 | |||
| 218 | /** |
||
| 219 | * @var bool |
||
| 220 | */ |
||
| 221 | private $doSortHtmlAttributes = true; |
||
| 222 | |||
| 223 | /** |
||
| 224 | * @var bool |
||
| 225 | */ |
||
| 226 | private $doRemoveDeprecatedScriptCharsetAttribute = true; |
||
| 227 | |||
| 228 | /** |
||
| 229 | * @var bool |
||
| 230 | */ |
||
| 231 | private $doRemoveDefaultAttributes = false; |
||
| 232 | |||
| 233 | /** |
||
| 234 | * @var bool |
||
| 235 | */ |
||
| 236 | private $doRemoveDeprecatedAnchorName = true; |
||
| 237 | |||
| 238 | /** |
||
| 239 | * @var bool |
||
| 240 | */ |
||
| 241 | private $doRemoveDeprecatedTypeFromStylesheetLink = true; |
||
| 242 | |||
| 243 | /** |
||
| 244 | * @var bool |
||
| 245 | */ |
||
| 246 | private $doRemoveDeprecatedTypeFromScriptTag = true; |
||
| 247 | |||
| 248 | /** |
||
| 249 | * @var bool |
||
| 250 | */ |
||
| 251 | private $doRemoveValueFromEmptyInput = true; |
||
| 252 | |||
| 253 | /** |
||
| 254 | * @var bool |
||
| 255 | */ |
||
| 256 | private $doRemoveEmptyAttributes = true; |
||
| 257 | |||
| 258 | /** |
||
| 259 | * @var bool |
||
| 260 | */ |
||
| 261 | private $doSumUpWhitespace = true; |
||
| 262 | |||
| 263 | /** |
||
| 264 | * @var bool |
||
| 265 | */ |
||
| 266 | private $doRemoveSpacesBetweenTags = false; |
||
| 267 | |||
| 268 | /** |
||
| 269 | * @var bool |
||
| 270 | */ |
||
| 271 | private $keepBrokenHtml = false; |
||
| 272 | |||
| 273 | /** |
||
| 274 | * @var bool |
||
| 275 | */ |
||
| 276 | private $withDocType = false; |
||
| 277 | |||
| 278 | /** |
||
| 279 | * @var HtmlMinDomObserverInterface[]|\SplObjectStorage |
||
| 280 | */ |
||
| 281 | private $domLoopObservers; |
||
| 282 | |||
| 283 | /** |
||
| 284 | * @var int |
||
| 285 | */ |
||
| 286 | private $protected_tags_counter = 0; |
||
| 287 | |||
| 288 | /** |
||
| 289 | * HtmlMin constructor. |
||
| 290 | */ |
||
| 291 | 55 | public function __construct() |
|
| 297 | |||
| 298 | /** |
||
| 299 | * @param HtmlMinDomObserverInterface $observer |
||
| 300 | * |
||
| 301 | * @return void |
||
| 302 | */ |
||
| 303 | 55 | public function attachObserverToTheDomLoop(HtmlMinDomObserverInterface $observer) |
|
| 307 | |||
| 308 | /** |
||
| 309 | * @param bool $doOptimizeAttributes |
||
| 310 | * |
||
| 311 | * @return $this |
||
| 312 | */ |
||
| 313 | 2 | public function doOptimizeAttributes(bool $doOptimizeAttributes = true): self |
|
| 319 | |||
| 320 | /** |
||
| 321 | * @param bool $doOptimizeViaHtmlDomParser |
||
| 322 | * |
||
| 323 | * @return $this |
||
| 324 | */ |
||
| 325 | 1 | public function doOptimizeViaHtmlDomParser(bool $doOptimizeViaHtmlDomParser = true): self |
|
| 331 | |||
| 332 | /** |
||
| 333 | * @param bool $doRemoveComments |
||
| 334 | * |
||
| 335 | * @return $this |
||
| 336 | */ |
||
| 337 | 3 | public function doRemoveComments(bool $doRemoveComments = true): self |
|
| 343 | |||
| 344 | /** |
||
| 345 | * @param bool $doRemoveDefaultAttributes |
||
| 346 | * |
||
| 347 | * @return $this |
||
| 348 | */ |
||
| 349 | 2 | public function doRemoveDefaultAttributes(bool $doRemoveDefaultAttributes = true): self |
|
| 355 | |||
| 356 | /** |
||
| 357 | * @param bool $doRemoveDeprecatedAnchorName |
||
| 358 | * |
||
| 359 | * @return $this |
||
| 360 | */ |
||
| 361 | 2 | public function doRemoveDeprecatedAnchorName(bool $doRemoveDeprecatedAnchorName = true): self |
|
| 367 | |||
| 368 | /** |
||
| 369 | * @param bool $doRemoveDeprecatedScriptCharsetAttribute |
||
| 370 | * |
||
| 371 | * @return $this |
||
| 372 | */ |
||
| 373 | 2 | public function doRemoveDeprecatedScriptCharsetAttribute(bool $doRemoveDeprecatedScriptCharsetAttribute = true): self |
|
| 379 | |||
| 380 | /** |
||
| 381 | * @param bool $doRemoveDeprecatedTypeFromScriptTag |
||
| 382 | * |
||
| 383 | * @return $this |
||
| 384 | */ |
||
| 385 | 2 | public function doRemoveDeprecatedTypeFromScriptTag(bool $doRemoveDeprecatedTypeFromScriptTag = true): self |
|
| 391 | |||
| 392 | /** |
||
| 393 | * @param bool $doRemoveDeprecatedTypeFromStylesheetLink |
||
| 394 | * |
||
| 395 | * @return $this |
||
| 396 | */ |
||
| 397 | 2 | public function doRemoveDeprecatedTypeFromStylesheetLink(bool $doRemoveDeprecatedTypeFromStylesheetLink = true): self |
|
| 403 | |||
| 404 | /** |
||
| 405 | * @param bool $doRemoveEmptyAttributes |
||
| 406 | * |
||
| 407 | * @return $this |
||
| 408 | */ |
||
| 409 | 2 | public function doRemoveEmptyAttributes(bool $doRemoveEmptyAttributes = true): self |
|
| 415 | |||
| 416 | /** |
||
| 417 | * @param bool $doRemoveHttpPrefixFromAttributes |
||
| 418 | * |
||
| 419 | * @return $this |
||
| 420 | */ |
||
| 421 | 6 | public function doRemoveHttpPrefixFromAttributes(bool $doRemoveHttpPrefixFromAttributes = true): self |
|
| 427 | |||
| 428 | /** |
||
| 429 | * @param bool $doRemoveHttpsPrefixFromAttributes |
||
| 430 | * |
||
| 431 | * @return $this |
||
| 432 | */ |
||
| 433 | 1 | public function doRemoveHttpsPrefixFromAttributes(bool $doRemoveHttpsPrefixFromAttributes = true): self |
|
| 439 | |||
| 440 | /** |
||
| 441 | * @param bool $keepPrefixOnExternalAttributes |
||
| 442 | * |
||
| 443 | * @return $this |
||
| 444 | */ |
||
| 445 | 1 | public function keepPrefixOnExternalAttributes(bool $keepPrefixOnExternalAttributes = true): self |
|
| 451 | |||
| 452 | /** |
||
| 453 | * @param bool $doMakeSameDomainLinksRelative |
||
| 454 | * |
||
| 455 | * @return $this |
||
| 456 | */ |
||
| 457 | 2 | public function doMakeSameDomainLinksRelative(bool $doMakeSameDomainLinksRelative = true): self |
|
| 463 | |||
| 464 | /** |
||
| 465 | * @param string $localDomain |
||
| 466 | * |
||
| 467 | * @return $this |
||
| 468 | */ |
||
| 469 | 2 | public function setLocalDomain(string $localDomain = ''): self |
|
| 475 | |||
| 476 | /** |
||
| 477 | * @param void |
||
| 478 | * |
||
| 479 | * @return $this->localDomain |
||
|
|
|||
| 480 | */ |
||
| 481 | 2 | public function getLocalDomain(): string |
|
| 485 | |||
| 486 | /** |
||
| 487 | * @param bool $doRemoveOmittedHtmlTags |
||
| 488 | * |
||
| 489 | * @return $this |
||
| 490 | */ |
||
| 491 | 1 | public function doRemoveOmittedHtmlTags(bool $doRemoveOmittedHtmlTags = true): self |
|
| 497 | |||
| 498 | /** |
||
| 499 | * @param bool $doRemoveOmittedQuotes |
||
| 500 | * |
||
| 501 | * @return $this |
||
| 502 | */ |
||
| 503 | 1 | public function doRemoveOmittedQuotes(bool $doRemoveOmittedQuotes = true): self |
|
| 509 | |||
| 510 | /** |
||
| 511 | * @param bool $doRemoveSpacesBetweenTags |
||
| 512 | * |
||
| 513 | * @return $this |
||
| 514 | */ |
||
| 515 | 1 | public function doRemoveSpacesBetweenTags(bool $doRemoveSpacesBetweenTags = true): self |
|
| 521 | |||
| 522 | /** |
||
| 523 | * @param bool $doRemoveValueFromEmptyInput |
||
| 524 | * |
||
| 525 | * @return $this |
||
| 526 | */ |
||
| 527 | 2 | public function doRemoveValueFromEmptyInput(bool $doRemoveValueFromEmptyInput = true): self |
|
| 533 | |||
| 534 | /** |
||
| 535 | * @param bool $doRemoveWhitespaceAroundTags |
||
| 536 | * |
||
| 537 | * @return $this |
||
| 538 | */ |
||
| 539 | 5 | public function doRemoveWhitespaceAroundTags(bool $doRemoveWhitespaceAroundTags = true): self |
|
| 545 | |||
| 546 | /** |
||
| 547 | * @param bool $doSortCssClassNames |
||
| 548 | * |
||
| 549 | * @return $this |
||
| 550 | */ |
||
| 551 | 2 | public function doSortCssClassNames(bool $doSortCssClassNames = true): self |
|
| 557 | |||
| 558 | /** |
||
| 559 | * @param bool $doSortHtmlAttributes |
||
| 560 | * |
||
| 561 | * @return $this |
||
| 562 | */ |
||
| 563 | 2 | public function doSortHtmlAttributes(bool $doSortHtmlAttributes = true): self |
|
| 569 | |||
| 570 | /** |
||
| 571 | * @param bool $doSumUpWhitespace |
||
| 572 | * |
||
| 573 | * @return $this |
||
| 574 | */ |
||
| 575 | 2 | public function doSumUpWhitespace(bool $doSumUpWhitespace = true): self |
|
| 581 | |||
| 582 | 51 | private function domNodeAttributesToString(\DOMNode $node): string |
|
| 643 | |||
| 644 | /** |
||
| 645 | * @param \DOMNode $node |
||
| 646 | * |
||
| 647 | * @return bool |
||
| 648 | */ |
||
| 649 | 50 | private function domNodeClosingTagOptional(\DOMNode $node): bool |
|
| 905 | |||
| 906 | 51 | protected function domNodeToString(\DOMNode $node): string |
|
| 1018 | |||
| 1019 | /** |
||
| 1020 | * @return array |
||
| 1021 | */ |
||
| 1022 | public function getDomainsToRemoveHttpPrefixFromAttributes(): array |
||
| 1026 | |||
| 1027 | /** |
||
| 1028 | * @return bool |
||
| 1029 | */ |
||
| 1030 | public function isDoOptimizeAttributes(): bool |
||
| 1034 | |||
| 1035 | /** |
||
| 1036 | * @return bool |
||
| 1037 | */ |
||
| 1038 | public function isDoOptimizeViaHtmlDomParser(): bool |
||
| 1042 | |||
| 1043 | /** |
||
| 1044 | * @return bool |
||
| 1045 | */ |
||
| 1046 | public function isDoRemoveComments(): bool |
||
| 1050 | |||
| 1051 | /** |
||
| 1052 | * @return bool |
||
| 1053 | */ |
||
| 1054 | 34 | public function isDoRemoveDefaultAttributes(): bool |
|
| 1058 | |||
| 1059 | /** |
||
| 1060 | * @return bool |
||
| 1061 | */ |
||
| 1062 | 34 | public function isDoRemoveDeprecatedAnchorName(): bool |
|
| 1066 | |||
| 1067 | /** |
||
| 1068 | * @return bool |
||
| 1069 | */ |
||
| 1070 | 34 | public function isDoRemoveDeprecatedScriptCharsetAttribute(): bool |
|
| 1074 | |||
| 1075 | /** |
||
| 1076 | * @return bool |
||
| 1077 | */ |
||
| 1078 | 34 | public function isDoRemoveDeprecatedTypeFromScriptTag(): bool |
|
| 1082 | |||
| 1083 | /** |
||
| 1084 | * @return bool |
||
| 1085 | */ |
||
| 1086 | 34 | public function isDoRemoveDeprecatedTypeFromStylesheetLink(): bool |
|
| 1090 | |||
| 1091 | /** |
||
| 1092 | * @return bool |
||
| 1093 | */ |
||
| 1094 | 34 | public function isDoRemoveEmptyAttributes(): bool |
|
| 1098 | |||
| 1099 | /** |
||
| 1100 | * @return bool |
||
| 1101 | */ |
||
| 1102 | 34 | public function isDoRemoveHttpPrefixFromAttributes(): bool |
|
| 1106 | |||
| 1107 | /** |
||
| 1108 | * @return bool |
||
| 1109 | */ |
||
| 1110 | 34 | public function isDoRemoveHttpsPrefixFromAttributes(): bool |
|
| 1114 | |||
| 1115 | /** |
||
| 1116 | * @return bool |
||
| 1117 | */ |
||
| 1118 | 4 | public function isKeepPrefixOnExternalAttributes(): bool |
|
| 1122 | |||
| 1123 | /** |
||
| 1124 | * @return bool |
||
| 1125 | */ |
||
| 1126 | 34 | public function isDoMakeSameDomainLinksRelative(): bool |
|
| 1130 | |||
| 1131 | /** |
||
| 1132 | * @return bool |
||
| 1133 | */ |
||
| 1134 | 2 | public function isLocalDomainSet(): bool |
|
| 1138 | |||
| 1139 | /** |
||
| 1140 | * @return bool |
||
| 1141 | */ |
||
| 1142 | public function isDoRemoveOmittedHtmlTags(): bool |
||
| 1146 | |||
| 1147 | /** |
||
| 1148 | * @return bool |
||
| 1149 | */ |
||
| 1150 | public function isDoRemoveOmittedQuotes(): bool |
||
| 1154 | |||
| 1155 | /** |
||
| 1156 | * @return bool |
||
| 1157 | */ |
||
| 1158 | public function isDoRemoveSpacesBetweenTags(): bool |
||
| 1162 | |||
| 1163 | /** |
||
| 1164 | * @return bool |
||
| 1165 | */ |
||
| 1166 | 34 | public function isDoRemoveValueFromEmptyInput(): bool |
|
| 1170 | |||
| 1171 | /** |
||
| 1172 | * @return bool |
||
| 1173 | */ |
||
| 1174 | public function isDoRemoveWhitespaceAroundTags(): bool |
||
| 1178 | |||
| 1179 | /** |
||
| 1180 | * @return bool |
||
| 1181 | */ |
||
| 1182 | 34 | public function isDoSortCssClassNames(): bool |
|
| 1186 | |||
| 1187 | /** |
||
| 1188 | * @return bool |
||
| 1189 | */ |
||
| 1190 | 34 | public function isDoSortHtmlAttributes(): bool |
|
| 1194 | |||
| 1195 | /** |
||
| 1196 | * @return bool |
||
| 1197 | */ |
||
| 1198 | public function isDoSumUpWhitespace(): bool |
||
| 1202 | |||
| 1203 | /** |
||
| 1204 | * @param string $html |
||
| 1205 | * @param bool $multiDecodeNewHtmlEntity |
||
| 1206 | * |
||
| 1207 | * @return string |
||
| 1208 | */ |
||
| 1209 | 55 | public function minify($html, $multiDecodeNewHtmlEntity = false): string |
|
| 1334 | |||
| 1335 | /** |
||
| 1336 | * @param \DOMNode $node |
||
| 1337 | * |
||
| 1338 | * @return \DOMNode|null |
||
| 1339 | */ |
||
| 1340 | 50 | protected function getNextSiblingOfTypeDOMElement(\DOMNode $node) |
|
| 1349 | |||
| 1350 | /** |
||
| 1351 | * Check if the current string is an conditional comment. |
||
| 1352 | * |
||
| 1353 | * INFO: since IE >= 10 conditional comment are not working anymore |
||
| 1354 | * |
||
| 1355 | * <!--[if expression]> HTML <![endif]--> |
||
| 1356 | * <![if expression]> HTML <![endif]> |
||
| 1357 | * |
||
| 1358 | * @param string $comment |
||
| 1359 | * |
||
| 1360 | * @return bool |
||
| 1361 | */ |
||
| 1362 | 4 | private function isConditionalComment($comment): bool |
|
| 1380 | |||
| 1381 | /** |
||
| 1382 | * @param string $html |
||
| 1383 | * @param bool $multiDecodeNewHtmlEntity |
||
| 1384 | * |
||
| 1385 | * @return string |
||
| 1386 | */ |
||
| 1387 | 51 | private function minifyHtmlDom($html, $multiDecodeNewHtmlEntity): string |
|
| 1465 | |||
| 1466 | /** |
||
| 1467 | * @param SimpleHtmlDomInterface $domElement |
||
| 1468 | * |
||
| 1469 | * @return void |
||
| 1470 | */ |
||
| 1471 | 51 | private function notifyObserversAboutDomElementAfterMinification(SimpleHtmlDomInterface $domElement) |
|
| 1477 | |||
| 1478 | /** |
||
| 1479 | * @param SimpleHtmlDomInterface $domElement |
||
| 1480 | * |
||
| 1481 | * @return void |
||
| 1482 | */ |
||
| 1483 | 51 | private function notifyObserversAboutDomElementBeforeMinification(SimpleHtmlDomInterface $domElement) |
|
| 1489 | |||
| 1490 | /** |
||
| 1491 | * @param HtmlDomParser $dom |
||
| 1492 | * @param string $selector |
||
| 1493 | * |
||
| 1494 | * @return HtmlDomParser |
||
| 1495 | */ |
||
| 1496 | 51 | private function protectTagHelper(HtmlDomParser $dom, string $selector): HtmlDomParser |
|
| 1514 | |||
| 1515 | /** |
||
| 1516 | * Prevent changes of inline "styles" and "scripts". |
||
| 1517 | * |
||
| 1518 | * @param HtmlDomParser $dom |
||
| 1519 | * |
||
| 1520 | * @return HtmlDomParser |
||
| 1521 | */ |
||
| 1522 | 51 | private function protectTags(HtmlDomParser $dom): HtmlDomParser |
|
| 1572 | |||
| 1573 | /** |
||
| 1574 | * Remove comments in the dom. |
||
| 1575 | * |
||
| 1576 | * @param HtmlDomParser $dom |
||
| 1577 | * |
||
| 1578 | * @return HtmlDomParser |
||
| 1579 | */ |
||
| 1580 | 49 | private function removeComments(HtmlDomParser $dom): HtmlDomParser |
|
| 1597 | |||
| 1598 | /** |
||
| 1599 | * Trim tags in the dom. |
||
| 1600 | * |
||
| 1601 | * @param SimpleHtmlDomInterface $element |
||
| 1602 | * |
||
| 1603 | * @return void |
||
| 1604 | */ |
||
| 1605 | 3 | private function removeWhitespaceAroundTags(SimpleHtmlDomInterface $element) |
|
| 1634 | |||
| 1635 | /** |
||
| 1636 | * Callback function for preg_replace_callback use. |
||
| 1637 | * |
||
| 1638 | * @param array $matches PREG matches |
||
| 1639 | * |
||
| 1640 | * @return string |
||
| 1641 | */ |
||
| 1642 | 9 | private function restoreProtectedHtml($matches): string |
|
| 1648 | |||
| 1649 | /** |
||
| 1650 | * @param array $domainsToRemoveHttpPrefixFromAttributes |
||
| 1651 | * |
||
| 1652 | * @return $this |
||
| 1653 | */ |
||
| 1654 | 2 | public function setDomainsToRemoveHttpPrefixFromAttributes($domainsToRemoveHttpPrefixFromAttributes): self |
|
| 1660 | |||
| 1661 | /** |
||
| 1662 | * Sum-up extra whitespace from dom-nodes. |
||
| 1663 | * |
||
| 1664 | * @param HtmlDomParser $dom |
||
| 1665 | * |
||
| 1666 | * @return HtmlDomParser |
||
| 1667 | */ |
||
| 1668 | 50 | private function sumUpWhitespace(HtmlDomParser $dom): HtmlDomParser |
|
| 1701 | |||
| 1702 | /** |
||
| 1703 | * WARNING: maybe bad for performance ... |
||
| 1704 | * |
||
| 1705 | * @param bool $keepBrokenHtml |
||
| 1706 | * |
||
| 1707 | * @return HtmlMin |
||
| 1708 | */ |
||
| 1709 | 2 | public function useKeepBrokenHtml(bool $keepBrokenHtml): self |
|
| 1715 | } |
||
| 1716 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.