Code Duplication    Length = 27-27 lines in 2 locations

src/voku/helper/XmlDomParser.php 2 locations

@@ 441-467 (lines=27) @@
438
     *
439
     * @return XmlDomParser
440
     */
441
    public function loadHtmlFile(string $filePath, $libXMLExtraOptions = null): DomParserInterface
442
    {
443
        if (
444
            !\preg_match("/^https?:\/\//i", $filePath)
445
            &&
446
            !\file_exists($filePath)
447
        ) {
448
            throw new \RuntimeException("File ${filePath} not found");
449
        }
450
451
        try {
452
            if (\class_exists('\voku\helper\UTF8')) {
453
                /** @noinspection PhpUndefinedClassInspection */
454
                $html = UTF8::file_get_contents($filePath);
455
            } else {
456
                $html = \file_get_contents($filePath);
457
            }
458
        } catch (\Exception $e) {
459
            throw new \RuntimeException("Could not load file ${filePath}");
460
        }
461
462
        if ($html === false) {
463
            throw new \RuntimeException("Could not load file ${filePath}");
464
        }
465
466
        return $this->loadHtml($html, $libXMLExtraOptions);
467
    }
468
469
    /**
470
     * @param string $selector
@@ 505-531 (lines=27) @@
502
     *
503
     * @return XmlDomParser
504
     */
505
    public function loadXmlFile(string $filePath, $libXMLExtraOptions = null): self
506
    {
507
        if (
508
            !\preg_match("/^https?:\/\//i", $filePath)
509
            &&
510
            !\file_exists($filePath)
511
        ) {
512
            throw new \RuntimeException("File ${filePath} not found");
513
        }
514
515
        try {
516
            if (\class_exists('\voku\helper\UTF8')) {
517
                /** @noinspection PhpUndefinedClassInspection */
518
                $xml = UTF8::file_get_contents($filePath);
519
            } else {
520
                $xml = \file_get_contents($filePath);
521
            }
522
        } catch (\Exception $e) {
523
            throw new \RuntimeException("Could not load file ${filePath}");
524
        }
525
526
        if ($xml === false) {
527
            throw new \RuntimeException("Could not load file ${filePath}");
528
        }
529
530
        return $this->loadXml($xml, $libXMLExtraOptions);
531
    }
532
533
    /**
534
     * @param callable      $callback