Code Duplication    Length = 37-38 lines in 2 locations

src/voku/helper/SimpleHtmlDom.php 1 location

@@ 161-198 (lines=38) @@
158
     *
159
     * @return SimpleHtmlDomInterface
160
     */
161
    protected function replaceChildWithString(string $string): SimpleHtmlDomInterface
162
    {
163
        if (!empty($string)) {
164
            $newDocument = new HtmlDomParser($string);
165
166
            $tmpDomString = $this->normalizeStringForComparision($newDocument);
167
            $tmpStr = $this->normalizeStringForComparision($string);
168
            if ($tmpDomString !== $tmpStr) {
169
                throw new \RuntimeException(
170
                    'Not valid HTML fragment!' . "\n" .
171
                    $tmpDomString . "\n" .
172
                    $tmpStr
173
                );
174
            }
175
        }
176
177
        if (\count($this->node->childNodes) > 0) {
178
            foreach ($this->node->childNodes as $node) {
179
                $this->node->removeChild($node);
180
            }
181
        }
182
183
        if (!empty($newDocument)) {
184
            $newDocument = $this->cleanHtmlWrapper($newDocument);
185
            $ownerDocument = $this->node->ownerDocument;
186
            if (
187
                $ownerDocument !== null
188
                &&
189
                $newDocument->getDocument()->documentElement !== null
190
            ) {
191
                $newNode = $ownerDocument->importNode($newDocument->getDocument()->documentElement, true);
192
                /** @noinspection UnusedFunctionResultInspection */
193
                $this->node->appendChild($newNode);
194
            }
195
        }
196
197
        return $this;
198
    }
199
200
    /**
201
     * Replace this node.

src/voku/helper/SimpleXmlDom.php 1 location

@@ 149-185 (lines=37) @@
146
     *
147
     * @return SimpleXmlDomInterface
148
     */
149
    protected function replaceChildWithString(string $string): SimpleXmlDomInterface
150
    {
151
        if (!empty($string)) {
152
            $newDocument = new XmlDomParser($string);
153
154
            $tmpDomString = $this->normalizeStringForComparision($newDocument);
155
            $tmpStr = $this->normalizeStringForComparision($string);
156
            if ($tmpDomString !== $tmpStr) {
157
                throw new \RuntimeException(
158
                    'Not valid HTML fragment!' . "\n" .
159
                    $tmpDomString . "\n" .
160
                    $tmpStr
161
                );
162
            }
163
        }
164
165
        if (\count($this->node->childNodes) > 0) {
166
            foreach ($this->node->childNodes as $node) {
167
                $this->node->removeChild($node);
168
            }
169
        }
170
171
        if (!empty($newDocument)) {
172
            $ownerDocument = $this->node->ownerDocument;
173
            if (
174
                $ownerDocument !== null
175
                &&
176
                $newDocument->getDocument()->documentElement !== null
177
            ) {
178
                $newNode = $ownerDocument->importNode($newDocument->getDocument()->documentElement, true);
179
                /** @noinspection UnusedFunctionResultInspection */
180
                $this->node->appendChild($newNode);
181
            }
182
        }
183
184
        return $this;
185
    }
186
187
    /**
188
     * Replace this node.