Completed
Push — master ( c9bbeb...1f0ecb )
by Ivan
03:21
created

AbstractElement::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 9.4286
cc 1
eloc 3
nc 1
nop 2
crap 2
1
<?php
2
3
namespace SP\Crawler\Element;
4
5
use SP\Crawler\Reader;
6
use DOMElement;
7
8
/**
9
 * @author    Ivan Kerin <[email protected]>
10
 * @copyright 2015, Clippings Ltd.
11
 * @license   http://spdx.org/licenses/BSD-3-Clause
12
 */
13
abstract class AbstractElement
14
{
15
    /**
16
     * @var DOMElement
17
     */
18
    private $element;
19
20
    /**
21
     * @var Reader
22
     */
23
    private $reader;
24
25
    /**
26
     * @param Reader     $reader
27
     * @param DOMElement $element
28
     */
29
    public function __construct(Reader $reader, DOMElement $element)
30
    {
31
        $this->element = $element;
32
        $this->reader = $reader;
33
    }
34
35
    /**
36
     * @return DOMElement
37
     */
38
    public function getElement()
39
    {
40
        return $this->element;
41
    }
42
43
    /**
44
     * @param  string  $name
45
     * @return boolean
46
     */
47
    public function hasAttribute($name)
48
    {
49
        return $this->element->hasAttribute($name);
50
    }
51
52
    /**
53
     * @param  string $name
54
     * @return string
55
     */
56
    public function getAttribute($name)
57
    {
58
        return $this->element->getAttribute($name);
59
    }
60
61
    /**
62
     * @param string $name
63
     * @param mixed $value
64
     */
65
    public function setAttribute($name, $value)
66
    {
67
        $this->element->setAttribute($name, $value);
68
    }
69
70
    /**
71
     * @param string $name
72
     */
73
    public function removeAttribute($name)
74
    {
75
        $this->element->removeAttribute($name);
76
    }
77
78
    /**
79
     * @return boolean
80
     */
81
    public function isDisabled()
82
    {
83
        return $this->element->hasAttribute('disabled');
84
    }
85
86
    /**
87
     * @return Reader
88
     */
89
    public function getReader()
90
    {
91
        return $this->reader;
92
    }
93
94
    /**
95
     * @param  string $xpath
96
     * @return DOMNodeList
97
     */
98
    public function getChildren($xpath)
99
    {
100
        return $this->reader->query($xpath, $this->element);
101
    }
102
103
    /**
104
     * @return string
105
     */
106
    public function getName()
107
    {
108
        return $this->getAttribute('name');
109
    }
110
}
111