Completed
Push — master ( 50075b...af0aea )
by Joseph
11:19
created

Node   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 7
c 3
b 0
f 2
lcom 1
cbo 0
dl 0
loc 37
rs 10

5 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
1
<?php
2
3
namespace Jclyons52\PHPQuery;
4
5
class Node
6
{
7
    public $node;
8
9
    public function __construct(\DOMNode $node)
10
    {
11
        $this->node = $node;
12
    }
13
14
    public function toString()
15
    {
16
        return $this->node->ownerDocument->saveHTML($this->node);
17
    }
18
19
    public function attr($name, $value = null)
20
    {
21
        if (!($this->node instanceof \DOMElement)) {
22
            throw new \Exception('dom node is not of type element');
23
        }
24
25
        if ($value) {
26
            $this->node->setAttribute($name, $value);
27
        }
28
        
29
        return $this->node->getAttribute($name);
30
    }
31
32
    public function text()
33
    {
34
        return $this->node->textContent;
35
    }
36
37
    public function remove()
38
    {
39
        $this->node->parentNode->removeChild($this->node);
40
    }
41
}
42