Passed
Push — master ( 8c2778...04210d )
by Domenico
02:17
created

HtmlParser::getNodeListFromQueryPath()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 2
eloc 6
c 1
b 1
f 0
nc 2
nop 0
dl 0
loc 11
rs 10
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * @author hashashiyyin [email protected] / [email protected]
5
 * Date: 23/04/24
6
 * Time: 16:45
7
 *
8
 */
9
10
namespace Matecat\XmlParser;
11
12
use ArrayObject;
13
use DOMException;
14
use DOMXPath;
15
use Matecat\XmlParser\Exception\InvalidXmlException;
16
use Matecat\XmlParser\Exception\XmlParsingException;
17
18
class HtmlParser extends AbstractParser {
19
20
    /**
21
     * This solution is taken from here and then modified:
22
     * https://www.php.net/manual/fr/regexp.reference.recursive.php#95568
23
     *
24
     * @param string $xml
25
     * @param bool   $isXmlFragment
26
     *
27
     * @return ArrayObject
28
     * @throws DOMException
29
     * @throws InvalidXmlException
30
     * @throws XmlParsingException
31
     */
32
    public static function parse( $xml, $isXmlFragment = false ) {
33
        $parser = new static( $xml, $isXmlFragment, true );
34
35
        return $parser->extractNodes();
36
    }
37
38
    /**
39
     * @return ArrayObject
40
     */
41
    protected function getNodeListFromQueryPath() {
42
43
        $xpath = new DOMXPath( $this->dom );
44
45
        if ( $this->isXmlFragment ) {
46
            $htmlNodeList = $xpath->query( "/" . self::fragmentDocumentRoot );
47
        } else {
48
            $htmlNodeList = $xpath->query( "/html" );
49
        }
50
51
        return $htmlNodeList;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $htmlNodeList returns the type DOMNodeList which is incompatible with the documented return type ArrayObject.
Loading history...
52
53
    }
54
55
}