@@ -435,12 +435,10 @@ private function getAllNodesWithStyleAttribute(): \DOMNodeList
435435 */
436436 private function normalizeStyleAttributes (\DOMElement $ node ): void
437437 {
438- $ declarationBlockParser = new DeclarationBlockParser ();
439-
440438 $ pattern = '/-{0,2}+[_a-zA-Z][ \\w \\-]*+(?=:)/S ' ;
441439 /** @param array<array-key, string> $propertyNameMatches */
442- $ callback = static function (array $ propertyNameMatches ) use ( $ declarationBlockParser ) : string {
443- return $ declarationBlockParser -> normalizePropertyName ($ propertyNameMatches [0 ]);
440+ $ callback = static function (array $ propertyNameMatches ): string {
441+ return DeclarationBlockParser:: normalizePropertyName ($ propertyNameMatches [0 ]);
444442 };
445443 if (\function_exists ('Safe \\preg_replace_callback ' )) {
446444 $ normalizedOriginalStyle = preg_replace_callback ($ pattern , $ callback , $ node ->getAttribute ('style ' ));
@@ -453,7 +451,7 @@ private function normalizeStyleAttributes(\DOMElement $node): void
453451 // In order to not overwrite existing style attributes in the HTML, we have to save the original HTML styles.
454452 $ nodePath = $ node ->getNodePath ();
455453 if (\is_string ($ nodePath ) && ($ nodePath !== '' ) && !isset ($ this ->styleAttributesForNodes [$ nodePath ])) {
456- $ this ->styleAttributesForNodes [$ nodePath ] = $ declarationBlockParser -> parse ($ normalizedOriginalStyle );
454+ $ this ->styleAttributesForNodes [$ nodePath ] = DeclarationBlockParser:: parse ($ normalizedOriginalStyle );
457455 $ this ->visitedNodes [$ nodePath ] = $ node ;
458456 }
459457
@@ -759,16 +757,15 @@ private function getCssSelectorPrecedence(string $selector): int
759757 private function copyInlinableCssToStyleAttribute (\DOMElement $ node , array $ cssRule ): void
760758 {
761759 $ declarationsBlock = $ cssRule ['declarationsBlock ' ];
762- $ declarationBlockParser = new DeclarationBlockParser ();
763- $ newStyleDeclarations = $ declarationBlockParser ->parse ($ declarationsBlock );
760+ $ newStyleDeclarations = DeclarationBlockParser::parse ($ declarationsBlock );
764761 if ($ newStyleDeclarations === []) {
765762 return ;
766763 }
767764
768765 // if it has a style attribute, get it, process it, and append (overwrite) new stuff
769766 if ($ node ->hasAttribute ('style ' )) {
770767 // break it up into an associative array
771- $ oldStyleDeclarations = $ declarationBlockParser -> parse ($ node ->getAttribute ('style ' ));
768+ $ oldStyleDeclarations = DeclarationBlockParser:: parse ($ node ->getAttribute ('style ' ));
772769 } else {
773770 $ oldStyleDeclarations = [];
774771 }
@@ -816,14 +813,13 @@ private function generateStyleStringFromDeclarationsArrays(array $oldStyles, arr
816813
817814 $ combinedStyles = \array_merge ($ oldStyles , $ newStyles );
818815
819- $ declarationBlockParser = new DeclarationBlockParser ();
820816 $ style = '' ;
821817 foreach ($ combinedStyles as $ attributeName => $ attributeValue ) {
822818 $ trimmedAttributeName = \trim ($ attributeName );
823819 if ($ trimmedAttributeName === '' ) {
824820 throw new \UnexpectedValueException ('An empty property name was encountered. ' , 1727046078 );
825821 }
826- $ propertyName = $ declarationBlockParser -> normalizePropertyName ($ trimmedAttributeName );
822+ $ propertyName = DeclarationBlockParser:: normalizePropertyName ($ trimmedAttributeName );
827823 $ propertyValue = \trim ($ attributeValue );
828824 $ style .= $ propertyName . ': ' . $ propertyValue . '; ' ;
829825 }
@@ -847,10 +843,9 @@ private function attributeValueIsImportant(string $attributeValue): bool
847843 */
848844 private function fillStyleAttributesWithMergedStyles (): void
849845 {
850- $ declarationBlockParser = new DeclarationBlockParser ();
851846 foreach ($ this ->styleAttributesForNodes as $ nodePath => $ styleAttributesForNode ) {
852847 $ node = $ this ->visitedNodes [$ nodePath ];
853- $ currentStyleAttributes = $ declarationBlockParser -> parse ($ node ->getAttribute ('style ' ));
848+ $ currentStyleAttributes = DeclarationBlockParser:: parse ($ node ->getAttribute ('style ' ));
854849 $ node ->setAttribute (
855850 'style ' ,
856851 $ this ->generateStyleStringFromDeclarationsArrays (
@@ -887,7 +882,7 @@ private function removeImportantAnnotationFromAllInlineStyles(): void
887882 private function removeImportantAnnotationFromNodeInlineStyle (\DOMElement $ node ): void
888883 {
889884 $ style = $ node ->getAttribute ('style ' );
890- $ inlineStyleDeclarations = ( new DeclarationBlockParser ())-> parse ((bool ) $ style ? $ style : '' );
885+ $ inlineStyleDeclarations = DeclarationBlockParser:: parse ((bool ) $ style ? $ style : '' );
891886 /** @var array<string, string> $regularStyleDeclarations */
892887 $ regularStyleDeclarations = [];
893888 /** @var array<string, string> $importantStyleDeclarations */
0 commit comments