Completed
Push — master ( 1f0ecb...bcc29d )
by Ivan
04:21
created

AbstractElement   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 10
c 2
b 1
f 1
lcom 1
cbo 1
dl 0
loc 98
ccs 24
cts 24
cp 1
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getElement() 0 4 1
A hasAttribute() 0 4 1
A getAttribute() 0 4 1
A setAttribute() 0 4 1
A removeAttribute() 0 4 1
A isDisabled() 0 4 1
A getReader() 0 4 1
A getChildren() 0 4 1
A getName() 0 4 1
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 1
    public function __construct(Reader $reader, DOMElement $element)
30
    {
31 1
        $this->element = $element;
32 1
        $this->reader = $reader;
33 1
    }
34
35
    /**
36
     * @return DOMElement
37
     */
38 1
    public function getElement()
39
    {
40 1
        return $this->element;
41
    }
42
43
    /**
44
     * @param  string  $name
45
     * @return boolean
46
     */
47 1
    public function hasAttribute($name)
48
    {
49 1
        return $this->element->hasAttribute($name);
50
    }
51
52
    /**
53
     * @param  string $name
54
     * @return string
55
     */
56 1
    public function getAttribute($name)
57
    {
58 1
        return $this->element->getAttribute($name);
59
    }
60
61
    /**
62
     * @param string $name
63
     * @param mixed $value
64
     */
65 1
    public function setAttribute($name, $value)
66
    {
67 1
        $this->element->setAttribute($name, $value);
68 1
    }
69
70
    /**
71
     * @param string $name
72
     */
73 1
    public function removeAttribute($name)
74
    {
75 1
        $this->element->removeAttribute($name);
76 1
    }
77
78
    /**
79
     * @return boolean
80
     */
81 1
    public function isDisabled()
82
    {
83 1
        return $this->element->hasAttribute('disabled');
84
    }
85
86
    /**
87
     * @return Reader
88
     */
89 1
    public function getReader()
90
    {
91 1
        return $this->reader;
92
    }
93
94
    /**
95
     * @param  string $xpath
96
     * @return DOMNodeList
97
     */
98 1
    public function getChildren($xpath)
99
    {
100 1
        return $this->reader->query($xpath, $this->element);
101
    }
102
103
    /**
104
     * @return string
105
     */
106 1
    public function getName()
107
    {
108 1
        return $this->getAttribute('name');
109
    }
110
}
111