Code Duplication    Length = 29-29 lines in 2 locations

src/voku/helper/XmlDomParser.php 1 location

@@ 191-219 (lines=29) @@
188
     *
189
     * @return SimpleXmlDomInterface|SimpleXmlDomInterface[]|SimpleXmlDomNodeInterface
190
     */
191
    public function find(string $selector, $idx = null)
192
    {
193
        $xPathQuery = SelectorConverter::toXPath($selector);
194
195
        $xPath = new \DOMXPath($this->document);
196
        $nodesList = $xPath->query($xPathQuery);
197
        $elements = new SimpleXmlDomNode();
198
199
        foreach ($nodesList as $node) {
200
            $elements[] = new SimpleXmlDom($node);
201
        }
202
203
        // return all elements
204
        if ($idx === null) {
205
            if (\count($elements) === 0) {
206
                return new SimpleXmlDomNodeBlank();
207
            }
208
209
            return $elements;
210
        }
211
212
        // handle negative values
213
        if ($idx < 0) {
214
            $idx = \count($elements) + $idx;
215
        }
216
217
        // return one element
218
        return $elements[$idx] ?? new SimpleXmlDomBlank();
219
    }
220
221
    /**
222
     * Find nodes with a CSS selector.

src/voku/helper/HtmlDomParser.php 1 location

@@ 347-375 (lines=29) @@
344
     *
345
     * @return SimpleHtmlDomInterface|SimpleHtmlDomInterface[]|SimpleHtmlDomNodeInterface
346
     */
347
    public function find(string $selector, $idx = null)
348
    {
349
        $xPathQuery = SelectorConverter::toXPath($selector);
350
351
        $xPath = new \DOMXPath($this->document);
352
        $nodesList = $xPath->query($xPathQuery);
353
        $elements = new SimpleHtmlDomNode();
354
355
        foreach ($nodesList as $node) {
356
            $elements[] = new SimpleHtmlDom($node);
357
        }
358
359
        // return all elements
360
        if ($idx === null) {
361
            if (\count($elements) === 0) {
362
                return new SimpleHtmlDomNodeBlank();
363
            }
364
365
            return $elements;
366
        }
367
368
        // handle negative values
369
        if ($idx < 0) {
370
            $idx = \count($elements) + $idx;
371
        }
372
373
        // return one element
374
        return $elements[$idx] ?? new SimpleHtmlDomBlank();
375
    }
376
377
    /**
378
     * Find nodes with a CSS selector.