From: Alexander Ebert Date: Mon, 8 May 2023 10:00:04 +0000 (+0200) Subject: Make the normalizer reusable by passing in the `\DOMXPath` for `normalize()` X-Git-Tag: 6.0.0_Alpha_1~136^2~5 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=bce08d6b43290398af942886a1f2c333838f4a03;p=GitHub%2FWoltLab%2FWCF.git Make the normalizer reusable by passing in the `\DOMXPath` for `normalize()` --- diff --git a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeNormalizer.class.php b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeNormalizer.class.php index 4bf2fdafab..85dc429555 100644 --- a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeNormalizer.class.php +++ b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeNormalizer.class.php @@ -14,26 +14,22 @@ use wcf\util\DOMUtil; */ final class HtmlOutputNodeNormalizer { - public function __construct(private readonly \DOMXPath $xpath) + public function normalize(\DOMXPath $xpath): void { - } - - public function normalize(): void - { - $this->normalizeBr(); + $this->normalizeBr($xpath); - $candidates = $this->getPossibleSpacerParagraphs(); + $candidates = $this->getPossibleSpacerParagraphs($xpath); $this->reduceSpacerParagraphs($candidates); } /** * @return list<\DOMElement> */ - private function getPossibleSpacerParagraphs(): array + private function getPossibleSpacerParagraphs(\DOMXpath $xpath): array { $paragraphs = []; - foreach ($this->xpath->query('//p') as $p) { + foreach ($xpath->query('//p') as $p) { \assert($p instanceof \DOMElement); if ($p->childNodes->length === 1) { @@ -96,9 +92,9 @@ final class HtmlOutputNodeNormalizer } } - private function normalizeBr(): void + private function normalizeBr(\DOMXpath $xpath): void { - foreach ($this->xpath->query('//br') as $br) { + foreach ($xpath->query('//br') as $br) { \assert($br instanceof \DOMElement); $this->unwrapBr($br); diff --git a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeProcessor.class.php b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeProcessor.class.php index bf2b41a81e..2a6a109505 100644 --- a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeProcessor.class.php +++ b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeProcessor.class.php @@ -97,7 +97,7 @@ class HtmlOutputNodeProcessor extends AbstractHtmlNodeProcessor $this->invokeHtmlNode(new HtmlOutputUnfurlUrlNode()); } - (new HtmlOutputNodeNormalizer($this->getXPath()))->normalize(); + (new HtmlOutputNodeNormalizer())->normalize($this->getXPath()); // dynamic node handlers $this->invokeNodeHandlers('wcf\system\html\output\node\HtmlOutputNode', ['woltlab-metacode']);