Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
24 / 24 |
|
100.00% |
13 / 13 |
CRAP | |
100.00% |
1 / 1 |
AbstractNode | |
100.00% |
24 / 24 |
|
100.00% |
13 / 13 |
18 | |
100.00% |
1 / 1 |
getIndent | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setIndent | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getParent | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setParent | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
addChild | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
addChildren | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
4 | |||
hasChildren | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
hasChildNodes | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getChild | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
getChildren | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getChildNodes | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
removeChild | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
removeChildren | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | /** |
3 | * Pop PHP Framework (http://www.popphp.org/) |
4 | * |
5 | * @link https://github.com/popphp/popphp-framework |
6 | * @author Nick Sagona, III <dev@nolainteractive.com> |
7 | * @copyright Copyright (c) 2009-2023 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
8 | * @license http://www.popphp.org/license New BSD License |
9 | */ |
10 | |
11 | /** |
12 | * @namespace |
13 | */ |
14 | namespace Pop\Dom; |
15 | |
16 | /** |
17 | * Abstract node class |
18 | * |
19 | * @category Pop |
20 | * @package Pop\Dom |
21 | * @author Nick Sagona, III <dev@nolainteractive.com> |
22 | * @copyright Copyright (c) 2009-2023 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
23 | * @license http://www.popphp.org/license New BSD License |
24 | * @version 3.3.0 |
25 | */ |
26 | abstract class AbstractNode |
27 | { |
28 | |
29 | /** |
30 | * Object child nodes |
31 | * @var array |
32 | */ |
33 | protected $childNodes = []; |
34 | |
35 | /** |
36 | * Indentation for formatting purposes |
37 | * @var string |
38 | */ |
39 | protected $indent = null; |
40 | |
41 | /** |
42 | * Child output |
43 | * @var string |
44 | */ |
45 | protected $output = null; |
46 | |
47 | /** |
48 | * Parent node |
49 | * @var AbstractNode |
50 | */ |
51 | protected $parent = null; |
52 | |
53 | /** |
54 | * Return the indent |
55 | * |
56 | * @return string |
57 | */ |
58 | public function getIndent() |
59 | { |
60 | return $this->indent; |
61 | } |
62 | |
63 | /** |
64 | * Set the indent |
65 | * |
66 | * @param string $indent |
67 | * @return mixed |
68 | */ |
69 | public function setIndent($indent) |
70 | { |
71 | $this->indent = $indent; |
72 | return $this; |
73 | } |
74 | |
75 | /** |
76 | * Return the parent node |
77 | * |
78 | * @return AbstractNode |
79 | */ |
80 | public function getParent() |
81 | { |
82 | return $this->parent; |
83 | } |
84 | |
85 | /** |
86 | * Set the parent node |
87 | * |
88 | * @param AbstractNode $parent |
89 | * @return AbstractNode |
90 | */ |
91 | public function setParent(AbstractNode $parent) |
92 | { |
93 | $this->parent = $parent; |
94 | return $this; |
95 | } |
96 | |
97 | /** |
98 | * Add a child to the object |
99 | * |
100 | * @param mixed $c |
101 | * @throws \InvalidArgumentException |
102 | * @return mixed |
103 | */ |
104 | public function addChild(Child $c) |
105 | { |
106 | $c->setParent($this); |
107 | $this->childNodes[] = $c; |
108 | return $this; |
109 | } |
110 | |
111 | /** |
112 | * Add children to the object |
113 | * |
114 | * @param $children |
115 | * @throws Exception |
116 | * @return mixed |
117 | */ |
118 | public function addChildren($children) |
119 | { |
120 | if (is_array($children)) { |
121 | foreach ($children as $child) { |
122 | $this->addChild($child); |
123 | } |
124 | } else if ($children instanceof Child) { |
125 | $this->addChild($children); |
126 | } else { |
127 | throw new Exception( |
128 | 'Error: The parameter passed must be an instance of Pop\Dom\Child or an array of Pop\Dom\Child instances.' |
129 | ); |
130 | } |
131 | |
132 | return $this; |
133 | } |
134 | |
135 | /** |
136 | * Get whether or not the child object has children |
137 | * |
138 | * @return boolean |
139 | */ |
140 | public function hasChildren() |
141 | { |
142 | return (count($this->childNodes) > 0); |
143 | } |
144 | |
145 | /** |
146 | * Get whether or not the child object has children (alias) |
147 | * |
148 | * @return boolean |
149 | */ |
150 | public function hasChildNodes() |
151 | { |
152 | return (count($this->childNodes) > 0); |
153 | } |
154 | |
155 | /** |
156 | * Get the child nodes of the object |
157 | * |
158 | * @param int $i |
159 | * @return Child |
160 | */ |
161 | public function getChild($i) |
162 | { |
163 | return (isset($this->childNodes[(int)$i])) ? $this->childNodes[(int)$i] : null; |
164 | } |
165 | |
166 | /** |
167 | * Get the child nodes of the object |
168 | * |
169 | * @return array |
170 | */ |
171 | public function getChildren() |
172 | { |
173 | return $this->childNodes; |
174 | } |
175 | |
176 | /** |
177 | * Get the child nodes of the object (alias) |
178 | * |
179 | * @return array |
180 | */ |
181 | public function getChildNodes() |
182 | { |
183 | return $this->childNodes; |
184 | } |
185 | |
186 | /** |
187 | * Remove all child nodes from the object |
188 | * |
189 | * @param int $i |
190 | * @return void |
191 | */ |
192 | public function removeChild($i) |
193 | { |
194 | if (isset($this->childNodes[$i])) { |
195 | unset($this->childNodes[$i]); |
196 | } |
197 | } |
198 | |
199 | /** |
200 | * Remove all child nodes from the object |
201 | * |
202 | * @return void |
203 | */ |
204 | public function removeChildren() |
205 | { |
206 | $this->childNodes = []; |
207 | } |
208 | |
209 | } |