Completed
Push — master ( cd70c7...30ef4b )
by Joseph
08:00
created

Node::toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Jclyons52\PHPQuery;
4
5
class Node
6
{
7
    public $node;
8
9 24
    public function __construct(\DOMNode $node)
10
    {
11 24
        $this->node = $node;
12 24
    }
13
14 6
    public function toString()
15
    {
16 6
        return $this->node->ownerDocument->saveHTML($this->node);
17
    }
18
19 9
    public function attr($name, $value = null)
20
    {
21 9
        if (!($this->node instanceof \DOMElement)) {
22 3
            throw new \Exception('dom node is not of type element');
23
        }
24
25 6
        if ($value) {
26 3
            $this->node->setAttribute($name, $value);
27 3
        }
28
        
29 6
        return $this->node->getAttribute($name);
30
    }
31
32 3
    public function text()
33
    {
34 3
        return $this->node->textContent;
35
    }
36
37 3
    public function remove()
38
    {
39 3
        $this->node->parentNode->removeChild($this->node);
40 3
    }
41
42
    public function hasClass($class)
43
    {
44
        $classes = explode(' ', $this->attr('class'));
45
46
        return in_array($class, $classes);
47
    }
48
}
49