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

Node::attr()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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