HtmlParser   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 9
c 1
b 1
f 0
dl 0
loc 34
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 4 1
A getNodeListFromQueryPath() 0 11 2
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
}