Node   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 0 Features 4
Metric Value
wmc 8
c 6
b 0
f 4
lcom 1
cbo 0
dl 0
loc 64
ccs 20
cts 20
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 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