Code Duplication    Length = 27-27 lines in 3 locations

src/voku/helper/XmlDomParser.php 2 locations

@@ 395-421 (lines=27) @@
392
     *
393
     * @return XmlDomParser
394
     */
395
    public function loadHtmlFile(string $filePath, $libXMLExtraOptions = null): DomParserInterface
396
    {
397
        if (
398
            !\preg_match("/^https?:\/\//i", $filePath)
399
            &&
400
            !\file_exists($filePath)
401
        ) {
402
            throw new \RuntimeException("File ${filePath} not found");
403
        }
404
405
        try {
406
            if (\class_exists('\voku\helper\UTF8')) {
407
                /** @noinspection PhpUndefinedClassInspection */
408
                $html = UTF8::file_get_contents($filePath);
409
            } else {
410
                $html = \file_get_contents($filePath);
411
            }
412
        } catch (\Exception $e) {
413
            throw new \RuntimeException("Could not load file ${filePath}");
414
        }
415
416
        if ($html === false) {
417
            throw new \RuntimeException("Could not load file ${filePath}");
418
        }
419
420
        return $this->loadHtml($html, $libXMLExtraOptions);
421
    }
422
423
    /**
424
     * @param string $selector
@@ 459-485 (lines=27) @@
456
     *
457
     * @return XmlDomParser
458
     */
459
    public function loadXmlFile(string $filePath, $libXMLExtraOptions = null): self
460
    {
461
        if (
462
            !\preg_match("/^https?:\/\//i", $filePath)
463
            &&
464
            !\file_exists($filePath)
465
        ) {
466
            throw new \RuntimeException("File ${filePath} not found");
467
        }
468
469
        try {
470
            if (\class_exists('\voku\helper\UTF8')) {
471
                /** @noinspection PhpUndefinedClassInspection */
472
                $xml = UTF8::file_get_contents($filePath);
473
            } else {
474
                $xml = \file_get_contents($filePath);
475
            }
476
        } catch (\Exception $e) {
477
            throw new \RuntimeException("Could not load file ${filePath}");
478
        }
479
480
        if ($xml === false) {
481
            throw new \RuntimeException("Could not load file ${filePath}");
482
        }
483
484
        return $this->loadXml($xml, $libXMLExtraOptions);
485
    }
486
487
    /**
488
     * @param callable      $callback

src/voku/helper/HtmlDomParser.php 1 location

@@ 671-697 (lines=27) @@
668
     *
669
     * @return HtmlDomParser
670
     */
671
    public function loadHtmlFile(string $filePath, $libXMLExtraOptions = null): DomParserInterface
672
    {
673
        if (
674
            !\preg_match("/^https?:\/\//i", $filePath)
675
            &&
676
            !\file_exists($filePath)
677
        ) {
678
            throw new \RuntimeException("File ${filePath} not found");
679
        }
680
681
        try {
682
            if (\class_exists('\voku\helper\UTF8')) {
683
                /** @noinspection PhpUndefinedClassInspection */
684
                $html = UTF8::file_get_contents($filePath);
685
            } else {
686
                $html = \file_get_contents($filePath);
687
            }
688
        } catch (\Exception $e) {
689
            throw new \RuntimeException("Could not load file ${filePath}");
690
        }
691
692
        if ($html === false) {
693
            throw new \RuntimeException("Could not load file ${filePath}");
694
        }
695
696
        return $this->loadHtml($html, $libXMLExtraOptions);
697
    }
698
699
    /**
700
     * @param string $html