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

Node   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 3
Metric Value
wmc 8
c 4
b 0
f 3
lcom 1
cbo 0
dl 0
loc 44
ccs 17
cts 17
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A toString() 0 4 1
A attr() 0 12 3
A text() 0 4 1
A remove() 0 4 1
A hasClass() 0 6 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