Node::remove()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 3
cts 3
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 39
    public function __construct(\DOMNode $node)
10
    {
11 39
        $this->node = $node;
12 39
    }
13
14
    /**
15
     * @return string
16
     */
17 6
    public function toString()
18
    {
19 6
        return $this->node->ownerDocument->saveHTML($this->node);
20
    }
21
22
    /**
23
     * @param string $name
24
     * @param string|null $value
25
     * @return string
26
     * @throws \Exception
27
     */
28 15
    public function attr($name, $value = null)
29
    {
30 15
        if (!($this->node instanceof \DOMElement)) {
31 3
            throw new \Exception('dom node is not of type element');
32
        }
33
34 12
        if ($value !== null) {
35 6
            $this->node->setAttribute($name, $value);
36 6
        }
37
        
38 12
        return $this->node->getAttribute($name);
39
    }
40
41
    /**
42
     * @return string
43
     */
44 6
    public function text()
45
    {
46 6
        return $this->node->textContent;
47
    }
48
    
49
    /**
50
     *
51
     */
52 3
    public function remove()
53
    {
54 3
        $this->node->parentNode->removeChild($this->node);
55 3
    }
56
57
    /**
58
     * @param string $class
59
     * @return bool
60
     * @throws \Exception
61
     */
62 3
    public function hasClass($class)
63
    {
64 3
        $classes = explode(' ', $this->attr('class'));
65
66 3
        return in_array($class, $classes);
67
    }
68
}
69