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 |
||
| 23 | class HtmlMin |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * @var string |
||
| 27 | */ |
||
| 28 | private static $regExSpace = "/[[:space:]]{2,}|[\r\n]+/u"; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var array |
||
| 32 | */ |
||
| 33 | private static $optional_end_tags = [ |
||
| 34 | 'html', |
||
| 35 | 'head', |
||
| 36 | 'body', |
||
| 37 | ]; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * // https://mathiasbynens.be/demo/javascript-mime-type |
||
| 41 | * // https://developer.mozilla.org/en/docs/Web/HTML/Element/script#attr-type |
||
| 42 | * |
||
| 43 | * @var array |
||
| 44 | */ |
||
| 45 | private static $executableScriptsMimeTypes = [ |
||
| 46 | 'text/javascript' => '', |
||
| 47 | 'text/ecmascript' => '', |
||
| 48 | 'text/jscript' => '', |
||
| 49 | 'application/javascript' => '', |
||
| 50 | 'application/x-javascript' => '', |
||
| 51 | 'application/ecmascript' => '', |
||
| 52 | ]; |
||
| 53 | |||
| 54 | private static $selfClosingTags = [ |
||
| 55 | 'area', |
||
| 56 | 'base', |
||
| 57 | 'basefont', |
||
| 58 | 'br', |
||
| 59 | 'col', |
||
| 60 | 'command', |
||
| 61 | 'embed', |
||
| 62 | 'frame', |
||
| 63 | 'hr', |
||
| 64 | 'img', |
||
| 65 | 'input', |
||
| 66 | 'isindex', |
||
| 67 | 'keygen', |
||
| 68 | 'link', |
||
| 69 | 'meta', |
||
| 70 | 'param', |
||
| 71 | 'source', |
||
| 72 | 'track', |
||
| 73 | 'wbr', |
||
| 74 | ]; |
||
| 75 | |||
| 76 | private static $trimWhitespaceFromTags = [ |
||
| 77 | 'article' => '', |
||
| 78 | 'br' => '', |
||
| 79 | 'div' => '', |
||
| 80 | 'footer' => '', |
||
| 81 | 'hr' => '', |
||
| 82 | 'nav' => '', |
||
| 83 | 'p' => '', |
||
| 84 | 'script' => '', |
||
| 85 | ]; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @var array |
||
| 89 | */ |
||
| 90 | private static $booleanAttributes = [ |
||
| 91 | 'allowfullscreen' => '', |
||
| 92 | 'async' => '', |
||
| 93 | 'autofocus' => '', |
||
| 94 | 'autoplay' => '', |
||
| 95 | 'checked' => '', |
||
| 96 | 'compact' => '', |
||
| 97 | 'controls' => '', |
||
| 98 | 'declare' => '', |
||
| 99 | 'default' => '', |
||
| 100 | 'defaultchecked' => '', |
||
| 101 | 'defaultmuted' => '', |
||
| 102 | 'defaultselected' => '', |
||
| 103 | 'defer' => '', |
||
| 104 | 'disabled' => '', |
||
| 105 | 'enabled' => '', |
||
| 106 | 'formnovalidate' => '', |
||
| 107 | 'hidden' => '', |
||
| 108 | 'indeterminate' => '', |
||
| 109 | 'inert' => '', |
||
| 110 | 'ismap' => '', |
||
| 111 | 'itemscope' => '', |
||
| 112 | 'loop' => '', |
||
| 113 | 'multiple' => '', |
||
| 114 | 'muted' => '', |
||
| 115 | 'nohref' => '', |
||
| 116 | 'noresize' => '', |
||
| 117 | 'noshade' => '', |
||
| 118 | 'novalidate' => '', |
||
| 119 | 'nowrap' => '', |
||
| 120 | 'open' => '', |
||
| 121 | 'pauseonexit' => '', |
||
| 122 | 'readonly' => '', |
||
| 123 | 'required' => '', |
||
| 124 | 'reversed' => '', |
||
| 125 | 'scoped' => '', |
||
| 126 | 'seamless' => '', |
||
| 127 | 'selected' => '', |
||
| 128 | 'sortable' => '', |
||
| 129 | 'truespeed' => '', |
||
| 130 | 'typemustmatch' => '', |
||
| 131 | 'visible' => '', |
||
| 132 | ]; |
||
| 133 | /** |
||
| 134 | * @var array |
||
| 135 | */ |
||
| 136 | private static $skipTagsForRemoveWhitespace = [ |
||
| 137 | 'code', |
||
| 138 | 'pre', |
||
| 139 | 'script', |
||
| 140 | 'style', |
||
| 141 | 'textarea', |
||
| 142 | ]; |
||
| 143 | |||
| 144 | /** |
||
| 145 | * @var array |
||
| 146 | */ |
||
| 147 | private $protectedChildNodes = []; |
||
| 148 | |||
| 149 | /** |
||
| 150 | * @var string |
||
| 151 | */ |
||
| 152 | private $protectedChildNodesHelper = 'html-min--voku--saved-content'; |
||
| 153 | |||
| 154 | /** |
||
| 155 | * @var bool |
||
| 156 | */ |
||
| 157 | private $doOptimizeViaHtmlDomParser = true; |
||
| 158 | |||
| 159 | /** |
||
| 160 | * @var bool |
||
| 161 | */ |
||
| 162 | private $doOptimizeAttributes = true; |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @var bool |
||
| 166 | */ |
||
| 167 | private $doRemoveComments = true; |
||
| 168 | |||
| 169 | /** |
||
| 170 | * @var bool |
||
| 171 | */ |
||
| 172 | private $doRemoveWhitespaceAroundTags = false; |
||
| 173 | |||
| 174 | /** |
||
| 175 | * @var bool |
||
| 176 | */ |
||
| 177 | private $doRemoveOmittedQuotes = true; |
||
| 178 | |||
| 179 | /** |
||
| 180 | * @var bool |
||
| 181 | */ |
||
| 182 | private $doRemoveOmittedHtmlTags = true; |
||
| 183 | |||
| 184 | /** |
||
| 185 | * @var bool |
||
| 186 | */ |
||
| 187 | private $doRemoveHttpPrefixFromAttributes = false; |
||
| 188 | |||
| 189 | /** |
||
| 190 | * @var array |
||
| 191 | */ |
||
| 192 | private $domainsToRemoveHttpPrefixFromAttributes = [ |
||
| 193 | 'google.com', |
||
| 194 | 'google.de', |
||
| 195 | ]; |
||
| 196 | |||
| 197 | /** |
||
| 198 | * @var bool |
||
| 199 | */ |
||
| 200 | private $doSortCssClassNames = true; |
||
| 201 | |||
| 202 | /** |
||
| 203 | * @var bool |
||
| 204 | */ |
||
| 205 | private $doSortHtmlAttributes = true; |
||
| 206 | |||
| 207 | /** |
||
| 208 | * @var bool |
||
| 209 | */ |
||
| 210 | private $doRemoveDeprecatedScriptCharsetAttribute = true; |
||
| 211 | |||
| 212 | /** |
||
| 213 | * @var bool |
||
| 214 | */ |
||
| 215 | private $doRemoveDefaultAttributes = false; |
||
| 216 | |||
| 217 | /** |
||
| 218 | * @var bool |
||
| 219 | */ |
||
| 220 | private $doRemoveDeprecatedAnchorName = true; |
||
| 221 | |||
| 222 | /** |
||
| 223 | * @var bool |
||
| 224 | */ |
||
| 225 | private $doRemoveDeprecatedTypeFromStylesheetLink = true; |
||
| 226 | |||
| 227 | /** |
||
| 228 | * @var bool |
||
| 229 | */ |
||
| 230 | private $doRemoveDeprecatedTypeFromScriptTag = true; |
||
| 231 | |||
| 232 | /** |
||
| 233 | * @var bool |
||
| 234 | */ |
||
| 235 | private $doRemoveValueFromEmptyInput = true; |
||
| 236 | |||
| 237 | /** |
||
| 238 | * @var bool |
||
| 239 | */ |
||
| 240 | private $doRemoveEmptyAttributes = true; |
||
| 241 | |||
| 242 | /** |
||
| 243 | * @var bool |
||
| 244 | */ |
||
| 245 | private $doSumUpWhitespace = true; |
||
| 246 | |||
| 247 | /** |
||
| 248 | * @var bool |
||
| 249 | */ |
||
| 250 | private $doRemoveSpacesBetweenTags = false; |
||
| 251 | |||
| 252 | /** |
||
| 253 | * @var bool |
||
| 254 | */ |
||
| 255 | private $keepBrokenHtml = false; |
||
| 256 | |||
| 257 | /** |
||
| 258 | * @var |
||
| 259 | */ |
||
| 260 | private $withDocType; |
||
| 261 | |||
| 262 | /** |
||
| 263 | * HtmlMin constructor. |
||
| 264 | */ |
||
| 265 | 36 | public function __construct() |
|
| 268 | |||
| 269 | /** |
||
| 270 | * @param boolean $doOptimizeAttributes |
||
| 271 | * |
||
| 272 | * @return $this |
||
| 273 | */ |
||
| 274 | 2 | public function doOptimizeAttributes(bool $doOptimizeAttributes = true): self |
|
| 280 | |||
| 281 | /** |
||
| 282 | * @param boolean $doOptimizeViaHtmlDomParser |
||
| 283 | * |
||
| 284 | * @return $this |
||
| 285 | */ |
||
| 286 | 1 | public function doOptimizeViaHtmlDomParser(bool $doOptimizeViaHtmlDomParser = true): self |
|
| 292 | |||
| 293 | /** |
||
| 294 | * @param boolean $doRemoveComments |
||
| 295 | * |
||
| 296 | * @return $this |
||
| 297 | */ |
||
| 298 | 3 | public function doRemoveComments(bool $doRemoveComments = true): self |
|
| 304 | |||
| 305 | /** |
||
| 306 | * @param boolean $doRemoveDefaultAttributes |
||
| 307 | * |
||
| 308 | * @return $this |
||
| 309 | */ |
||
| 310 | 2 | public function doRemoveDefaultAttributes(bool $doRemoveDefaultAttributes = true): self |
|
| 316 | |||
| 317 | /** |
||
| 318 | * @param boolean $doRemoveDeprecatedAnchorName |
||
| 319 | * |
||
| 320 | * @return $this |
||
| 321 | */ |
||
| 322 | 2 | public function doRemoveDeprecatedAnchorName(bool $doRemoveDeprecatedAnchorName = true): self |
|
| 328 | |||
| 329 | /** |
||
| 330 | * @param boolean $doRemoveDeprecatedScriptCharsetAttribute |
||
| 331 | * |
||
| 332 | * @return $this |
||
| 333 | */ |
||
| 334 | 2 | public function doRemoveDeprecatedScriptCharsetAttribute(bool $doRemoveDeprecatedScriptCharsetAttribute = true): self |
|
| 340 | |||
| 341 | /** |
||
| 342 | * @param boolean $doRemoveDeprecatedTypeFromScriptTag |
||
| 343 | * |
||
| 344 | * @return $this |
||
| 345 | */ |
||
| 346 | 2 | public function doRemoveDeprecatedTypeFromScriptTag(bool $doRemoveDeprecatedTypeFromScriptTag = true): self |
|
| 352 | |||
| 353 | /** |
||
| 354 | * @param boolean $doRemoveDeprecatedTypeFromStylesheetLink |
||
| 355 | * |
||
| 356 | * @return $this |
||
| 357 | */ |
||
| 358 | 2 | public function doRemoveDeprecatedTypeFromStylesheetLink(bool $doRemoveDeprecatedTypeFromStylesheetLink = true): self |
|
| 364 | |||
| 365 | /** |
||
| 366 | * @param boolean $doRemoveEmptyAttributes |
||
| 367 | * |
||
| 368 | * @return $this |
||
| 369 | */ |
||
| 370 | 2 | public function doRemoveEmptyAttributes(bool $doRemoveEmptyAttributes = true): self |
|
| 376 | |||
| 377 | /** |
||
| 378 | * @param boolean $doRemoveHttpPrefixFromAttributes |
||
| 379 | * |
||
| 380 | * @return $this |
||
| 381 | */ |
||
| 382 | 4 | public function doRemoveHttpPrefixFromAttributes(bool $doRemoveHttpPrefixFromAttributes = true): self |
|
| 388 | |||
| 389 | /** |
||
| 390 | * @param boolean $doRemoveSpacesBetweenTags |
||
| 391 | * |
||
| 392 | * @return $this |
||
| 393 | */ |
||
| 394 | public function doRemoveSpacesBetweenTags(bool $doRemoveSpacesBetweenTags = true): self |
||
| 400 | |||
| 401 | /** |
||
| 402 | * @param boolean $doRemoveValueFromEmptyInput |
||
| 403 | * |
||
| 404 | * @return $this |
||
| 405 | */ |
||
| 406 | 2 | public function doRemoveValueFromEmptyInput(bool $doRemoveValueFromEmptyInput = true): self |
|
| 412 | |||
| 413 | /** |
||
| 414 | * @param boolean $doRemoveWhitespaceAroundTags |
||
| 415 | * |
||
| 416 | * @return $this |
||
| 417 | */ |
||
| 418 | 4 | public function doRemoveWhitespaceAroundTags(bool $doRemoveWhitespaceAroundTags = true): self |
|
| 424 | |||
| 425 | /** |
||
| 426 | * @param bool $doRemoveOmittedQuotes |
||
| 427 | * |
||
| 428 | * @return $this |
||
| 429 | */ |
||
| 430 | 1 | public function doRemoveOmittedQuotes(bool $doRemoveOmittedQuotes = true): self |
|
| 436 | |||
| 437 | /** |
||
| 438 | * @param bool $doRemoveOmittedHtmlTags |
||
| 439 | * |
||
| 440 | * @return $this |
||
| 441 | */ |
||
| 442 | 1 | public function doRemoveOmittedHtmlTags(bool $doRemoveOmittedHtmlTags = true): self |
|
| 448 | |||
| 449 | /** |
||
| 450 | * @param boolean $doSortCssClassNames |
||
| 451 | * |
||
| 452 | * @return $this |
||
| 453 | */ |
||
| 454 | 2 | public function doSortCssClassNames(bool $doSortCssClassNames = true): self |
|
| 460 | |||
| 461 | /** |
||
| 462 | * @param boolean $doSortHtmlAttributes |
||
| 463 | * |
||
| 464 | * @return $this |
||
| 465 | */ |
||
| 466 | 2 | public function doSortHtmlAttributes(bool $doSortHtmlAttributes = true): self |
|
| 472 | |||
| 473 | /** |
||
| 474 | * @param boolean $doSumUpWhitespace |
||
| 475 | * |
||
| 476 | * @return $this |
||
| 477 | */ |
||
| 478 | 2 | public function doSumUpWhitespace(bool $doSumUpWhitespace = true): self |
|
| 484 | |||
| 485 | 32 | private function domNodeAttributesToString(\DOMNode $node): string |
|
| 519 | |||
| 520 | /** |
||
| 521 | * @param \DOMNode $node |
||
| 522 | * |
||
| 523 | * @return bool |
||
| 524 | */ |
||
| 525 | 31 | private function domNodeClosingTagOptional(\DOMNode $node): bool |
|
| 744 | |||
| 745 | 32 | protected function domNodeToString(\DOMNode $node): string |
|
| 746 | { |
||
| 747 | // init |
||
| 748 | 32 | $html = ''; |
|
| 749 | 32 | $emptyStringTmp = ''; |
|
| 750 | |||
| 751 | 32 | foreach ($node->childNodes as $child) { |
|
| 752 | |||
| 753 | 32 | if ($emptyStringTmp === 'is_empty') { |
|
| 754 | 19 | $emptyStringTmp = 'last_was_empty'; |
|
| 755 | } else { |
||
| 756 | 32 | $emptyStringTmp = ''; |
|
| 757 | } |
||
| 758 | |||
| 759 | 32 | if ($child instanceof \DOMDocumentType) { |
|
| 760 | |||
| 761 | // add the doc-type only if it wasn't generated by DomDocument |
||
| 762 | 9 | if ($this->withDocType !== true) { |
|
| 763 | continue; |
||
| 764 | } |
||
| 765 | |||
| 766 | 9 | if ($child->name) { |
|
| 767 | |||
| 768 | 9 | if (!$child->publicId && $child->systemId) { |
|
| 769 | $tmpTypeSystem = 'SYSTEM'; |
||
| 770 | $tmpTypePublic = ''; |
||
| 771 | } else { |
||
| 772 | 9 | $tmpTypeSystem = ''; |
|
| 773 | 9 | $tmpTypePublic = 'PUBLIC'; |
|
| 774 | } |
||
| 775 | |||
| 776 | 9 | $html .= '<!DOCTYPE ' . $child->name . '' |
|
| 777 | 9 | . ($child->publicId ? ' ' . $tmpTypePublic . ' "' . $child->publicId . '"' : '') |
|
| 778 | 9 | . ($child->systemId ? ' ' . $tmpTypeSystem . ' "' . $child->systemId . '"' : '') |
|
| 779 | 9 | . '>'; |
|
| 780 | } |
||
| 781 | |||
| 782 | 32 | } elseif ($child instanceof \DOMElement) { |
|
| 783 | |||
| 784 | 32 | $html .= \rtrim('<' . $child->tagName . ' ' . $this->domNodeAttributesToString($child)); |
|
| 785 | 32 | $html .= '>' . $this->domNodeToString($child); |
|
| 786 | |||
| 787 | if ( |
||
| 788 | 32 | $this->doRemoveOmittedHtmlTags === false |
|
| 789 | || |
||
| 790 | 32 | !$this->domNodeClosingTagOptional($child) |
|
| 791 | ) { |
||
| 792 | 28 | $html .= '</' . $child->tagName . '>'; |
|
| 793 | } |
||
| 794 | |||
| 795 | 32 | if ($this->doRemoveWhitespaceAroundTags === false) { |
|
| 796 | if ( |
||
| 797 | 31 | $child->nextSibling instanceof \DOMText |
|
| 798 | && |
||
| 799 | 31 | $child->nextSibling->wholeText === ' ' |
|
| 800 | ) { |
||
| 801 | if ( |
||
| 802 | 18 | $emptyStringTmp !== 'last_was_empty' |
|
| 803 | && |
||
| 804 | 18 | substr($html, -1) !== ' ' |
|
| 805 | ) { |
||
| 806 | 18 | $html .= ' '; |
|
| 807 | } |
||
| 808 | 32 | $emptyStringTmp = 'is_empty'; |
|
| 809 | } |
||
| 810 | } |
||
| 811 | |||
| 812 | 28 | } elseif ($child instanceof \DOMText) { |
|
| 813 | |||
| 814 | 28 | if ($child->isElementContentWhitespace()) { |
|
| 815 | if ( |
||
| 816 | 21 | $child->previousSibling !== null |
|
| 817 | && |
||
| 818 | 21 | $child->nextSibling !== null |
|
| 819 | ) { |
||
| 820 | if ( |
||
| 821 | 14 | $emptyStringTmp !== 'last_was_empty' |
|
| 822 | && |
||
| 823 | 14 | substr($html, -1) !== ' ' |
|
| 824 | ) { |
||
| 825 | 5 | $html .= ' '; |
|
| 826 | } |
||
| 827 | 21 | $emptyStringTmp = 'is_empty'; |
|
| 828 | } |
||
| 829 | |||
| 830 | } else { |
||
| 831 | |||
| 832 | 28 | $html .= $child->wholeText; |
|
| 833 | |||
| 834 | } |
||
| 835 | |||
| 836 | 1 | } elseif ($child instanceof \DOMComment) { |
|
| 837 | |||
| 838 | 32 | $html .= '<!--' . $child->textContent . '-->'; |
|
| 839 | |||
| 840 | } |
||
| 841 | } |
||
| 842 | |||
| 843 | 32 | return $html; |
|
| 844 | } |
||
| 845 | |||
| 846 | /** |
||
| 847 | * @param \DOMNode $node |
||
| 848 | * |
||
| 849 | * @return \DOMNode|null |
||
| 850 | */ |
||
| 851 | 31 | protected function getNextSiblingOfTypeDOMElement(\DOMNode $node) |
|
| 859 | |||
| 860 | /** |
||
| 861 | * Check if the current string is an conditional comment. |
||
| 862 | * |
||
| 863 | * INFO: since IE >= 10 conditional comment are not working anymore |
||
| 864 | * |
||
| 865 | * <!--[if expression]> HTML <![endif]--> |
||
| 866 | * <![if expression]> HTML <![endif]> |
||
| 867 | * |
||
| 868 | * @param string $comment |
||
| 869 | * |
||
| 870 | * @return bool |
||
| 871 | */ |
||
| 872 | 4 | private function isConditionalComment($comment): bool |
|
| 884 | |||
| 885 | /** |
||
| 886 | * @param string $html |
||
| 887 | * @param bool $decodeUtf8Specials <p>Use this only in special cases, e.g. for PHP 5.3</p> |
||
| 888 | * |
||
| 889 | * @return string |
||
| 890 | */ |
||
| 891 | 36 | public function minify($html, $decodeUtf8Specials = false): string |
|
| 1015 | |||
| 1016 | /** |
||
| 1017 | * @param $html |
||
| 1018 | * @param $decodeUtf8Specials |
||
| 1019 | * |
||
| 1020 | * @return string |
||
| 1021 | */ |
||
| 1022 | 32 | private function minifyHtmlDom($html, $decodeUtf8Specials): string |
|
| 1088 | |||
| 1089 | /** |
||
| 1090 | * Sort HTML-Attributes, so that gzip can do better work and remove some default attributes... |
||
| 1091 | * |
||
| 1092 | * @param SimpleHtmlDom $element |
||
| 1093 | * |
||
| 1094 | * @return bool |
||
| 1095 | */ |
||
| 1096 | 31 | private function optimizeAttributes(SimpleHtmlDom $element): bool |
|
| 1155 | |||
| 1156 | /** |
||
| 1157 | * Prevent changes of inline "styles" and "scripts". |
||
| 1158 | * |
||
| 1159 | * @param HtmlDomParser $dom |
||
| 1160 | * |
||
| 1161 | * @return HtmlDomParser |
||
| 1162 | */ |
||
| 1163 | 32 | private function protectTags(HtmlDomParser $dom): HtmlDomParser |
|
| 1208 | |||
| 1209 | /** |
||
| 1210 | * Check if the attribute can be removed. |
||
| 1211 | * |
||
| 1212 | * @param string $tag |
||
| 1213 | * @param string $attrName |
||
| 1214 | * @param string $attrValue |
||
| 1215 | * @param array $allAttr |
||
| 1216 | * |
||
| 1217 | * @return bool |
||
| 1218 | */ |
||
| 1219 | 19 | private function removeAttributeHelper($tag, $attrName, $attrValue, $allAttr): bool |
|
| 1285 | |||
| 1286 | /** |
||
| 1287 | * Remove comments in the dom. |
||
| 1288 | * |
||
| 1289 | * @param HtmlDomParser $dom |
||
| 1290 | * |
||
| 1291 | * @return HtmlDomParser |
||
| 1292 | */ |
||
| 1293 | 30 | private function removeComments(HtmlDomParser $dom): HtmlDomParser |
|
| 1307 | |||
| 1308 | /** |
||
| 1309 | * Trim tags in the dom. |
||
| 1310 | * |
||
| 1311 | * @param SimpleHtmlDom $element |
||
| 1312 | * |
||
| 1313 | * @return void |
||
| 1314 | */ |
||
| 1315 | 3 | private function removeWhitespaceAroundTags(SimpleHtmlDom $element) |
|
| 1339 | |||
| 1340 | /** |
||
| 1341 | * Callback function for preg_replace_callback use. |
||
| 1342 | * |
||
| 1343 | * @param array $matches PREG matches |
||
| 1344 | * |
||
| 1345 | * @return string |
||
| 1346 | */ |
||
| 1347 | 2 | private function restoreProtectedHtml($matches): string |
|
| 1358 | |||
| 1359 | /** |
||
| 1360 | * WARNING: maybe bad for performance ... |
||
| 1361 | * |
||
| 1362 | * @param bool $keepBrokenHtml |
||
| 1363 | * |
||
| 1364 | * @return HtmlMin |
||
| 1365 | */ |
||
| 1366 | 1 | public function useKeepBrokenHtml(bool $keepBrokenHtml): self |
|
| 1372 | |||
| 1373 | /** |
||
| 1374 | * @param array $domainsToRemoveHttpPrefixFromAttributes |
||
| 1375 | * |
||
| 1376 | * @return $this |
||
| 1377 | */ |
||
| 1378 | 2 | public function setDomainsToRemoveHttpPrefixFromAttributes($domainsToRemoveHttpPrefixFromAttributes): self |
|
| 1384 | |||
| 1385 | /** |
||
| 1386 | * @param $attrName |
||
| 1387 | * @param $attrValue |
||
| 1388 | * |
||
| 1389 | * @return string |
||
| 1390 | */ |
||
| 1391 | 19 | private function sortCssClassNames($attrName, $attrValue): string |
|
| 1415 | |||
| 1416 | /** |
||
| 1417 | * Sum-up extra whitespace from dom-nodes. |
||
| 1418 | * |
||
| 1419 | * @param HtmlDomParser $dom |
||
| 1420 | * |
||
| 1421 | * @return HtmlDomParser |
||
| 1422 | */ |
||
| 1423 | 31 | private function sumUpWhitespace(HtmlDomParser $dom): HtmlDomParser |
|
| 1449 | } |
||
| 1450 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.