Completed
Push — master ( 1d52ac...913a22 )
by Joseph
14:38
created

Node::toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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