Document   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 0 Features 3
Metric Value
wmc 5
c 5
b 0
f 3
lcom 2
cbo 3
dl 0
loc 63
ccs 23
cts 23
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A querySelector() 0 11 1
A querySelectorAll() 0 17 2
A toString() 0 5 1
1
<?php
2
3
namespace Jclyons52\PHPQuery;
4
5
use Jclyons52\PHPQuery\Support\NodeCollection;
6
use Symfony\Component\CssSelector\CssSelectorConverter;
7
8
class Document
9
{
10
11
    private $dom;
12
13
    private $xpath;
14
15 42
    public function __construct($html)
16
    {
17 42
        $this->dom = new \DOMDocument();
18
19 42
        $this->dom->loadHtml($html);
20
21 42
        $this->xpath = new \DOMXPath($this->dom);
22 42
    }
23
24
    /**
25
     * @param string $selector
26
     * @return Node
27
     */
28 24
    public function querySelector($selector)
29
    {
30 24
        $converter = new CssSelectorConverter();
31
32 24
        $xpathQuery = $converter->toXPath($selector);
33
34 24
        $result = $this->xpath->query($xpathQuery);
35
36 24
        return new Node($result->item(0));
37
38
    }
39
40
    /**
41
     * @param string $selector
42
     * @return NodeCollection
43
     */
44 21
    public function querySelectorAll($selector)
45 3
    {
46 21
        $converter = new CssSelectorConverter();
47
48 18
        $xpathQuery = $converter->toXPath($selector);
49
50 18
        $results = $this->xpath->query($xpathQuery);
51
52 18
        $return = new NodeCollection();
53
54 18
        for ($i = 0; $i < $results->length; $i++) {
55 18
            $node = new Node($results->item($i));
56 18
            $return->append($node);
57 18
        }
58
59 18
        return $return;
60
    }
61
62
    /**
63
     * @return string
64
     */
65 3
    public function toString()
66
    {
67 3
        return $this->dom->saveHTML();
68
69
    }
70
}
71