@@ -39,8 +39,8 @@ |
||
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | - * @param $selector |
|
43 | - * @param $index |
|
42 | + * @param string|null $selector |
|
43 | + * @param null|integer $index |
|
44 | 44 | * @param string $property |
45 | 45 | * @param int $nodeType |
46 | 46 | * |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * @extends \DOMNode |
19 | 19 | */ |
20 | -trait TraversalTrait{ |
|
20 | +trait TraversalTrait { |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * @link http://php.net/manual/class.domnode.php#domnode.props.ownerdocument |
@@ -46,9 +46,9 @@ discard block |
||
46 | 46 | * |
47 | 47 | * @return \DOMNode|null |
48 | 48 | */ |
49 | - public function _recursivelyFind($selector, $index, string $property, int $nodeType = XML_ELEMENT_NODE){ |
|
49 | + public function _recursivelyFind($selector, $index, string $property, int $nodeType = XML_ELEMENT_NODE) { |
|
50 | 50 | |
51 | - if(is_numeric($selector)){ |
|
51 | + if (is_numeric($selector)) { |
|
52 | 52 | $index = $selector; |
53 | 53 | $selector = null; |
54 | 54 | } |
@@ -91,13 +91,13 @@ discard block |
||
91 | 91 | * |
92 | 92 | * @return \DOMNode|null |
93 | 93 | */ |
94 | - public function down($expression = null, int $index = 0){ |
|
94 | + public function down($expression = null, int $index = 0) { |
|
95 | 95 | |
96 | - if(count(func_get_args()) === 0){ |
|
96 | + if (count(func_get_args()) === 0) { |
|
97 | 97 | return $this->firstDescendant(); |
98 | 98 | } |
99 | 99 | |
100 | - if(is_numeric($expression)){ |
|
100 | + if (is_numeric($expression)) { |
|
101 | 101 | $index = $expression; |
102 | 102 | $expression = '*'; |
103 | 103 | } |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * |
112 | 112 | * @return \DOMNode|null |
113 | 113 | */ |
114 | - public function up($expression = null, int $index = null){ |
|
114 | + public function up($expression = null, int $index = null) { |
|
115 | 115 | return $this->_recursivelyFind($expression, $index, 'parentNode'); |
116 | 116 | } |
117 | 117 | |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * |
122 | 122 | * @return \DOMNode|null |
123 | 123 | */ |
124 | - public function previous($expression = null, int $index = null){ |
|
124 | + public function previous($expression = null, int $index = null) { |
|
125 | 125 | return $this->_recursivelyFind($expression, $index, 'previousSibling'); |
126 | 126 | } |
127 | 127 | |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | * |
132 | 132 | * @return \DOMNode|null |
133 | 133 | */ |
134 | - public function next($expression = null, int $index = null){ |
|
134 | + public function next($expression = null, int $index = null) { |
|
135 | 135 | return $this->_recursivelyFind($expression, $index, 'nextSibling'); |
136 | 136 | } |
137 | 137 | |
@@ -143,11 +143,11 @@ discard block |
||
143 | 143 | public function childElements(int $nodeType = XML_ELEMENT_NODE):NodeList{ |
144 | 144 | $children = new NodeList; |
145 | 145 | |
146 | - if($this->hasChildNodes()){ |
|
146 | + if ($this->hasChildNodes()) { |
|
147 | 147 | |
148 | - foreach($this->childNodes as $child){ |
|
148 | + foreach ($this->childNodes as $child) { |
|
149 | 149 | |
150 | - if($child->nodeType === $nodeType){ |
|
150 | + if ($child->nodeType === $nodeType) { |
|
151 | 151 | $children[] = $child; |
152 | 152 | } |
153 | 153 | |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | /** |
192 | 192 | * @return \DOMNode|null |
193 | 193 | */ |
194 | - public function firstDescendant(){ |
|
194 | + public function firstDescendant() { |
|
195 | 195 | return $this->descendants()[0] ?? null; |
196 | 196 | } |
197 | 197 |
@@ -14,4 +14,4 @@ |
||
14 | 14 | |
15 | 15 | use DOMAttr; |
16 | 16 | |
17 | -class Attr extends DOMAttr{} |
|
17 | +class Attr extends DOMAttr {} |
@@ -14,4 +14,4 @@ |
||
14 | 14 | |
15 | 15 | use DOMComment; |
16 | 16 | |
17 | -class Comment extends DOMComment{} |
|
17 | +class Comment extends DOMComment {} |
@@ -16,6 +16,6 @@ |
||
16 | 16 | |
17 | 17 | /** |
18 | 18 | */ |
19 | -class DocumentFragment extends DOMDocumentFragment{ |
|
19 | +class DocumentFragment extends DOMDocumentFragment { |
|
20 | 20 | use TraversalTrait, ManipulationTrait; |
21 | 21 | } |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | use DOMDocument, DOMNode, DOMNodeList, DOMXPath; |
16 | 16 | use Symfony\Component\CssSelector\CssSelectorConverter; |
17 | 17 | |
18 | -class Document extends DOMDocument{ |
|
18 | +class Document extends DOMDocument { |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * Document constructor. |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * @param string|null $version |
24 | 24 | * @param string|null $encoding |
25 | 25 | */ |
26 | - public function __construct($version = null, $encoding = null){ |
|
26 | + public function __construct($version = null, $encoding = null) { |
|
27 | 27 | parent::__construct($version, $encoding); |
28 | 28 | |
29 | 29 | $this->registerNodeClass('DOMElement', Element::class); |
@@ -76,21 +76,21 @@ discard block |
||
76 | 76 | */ |
77 | 77 | public function select($selectors = null, DOMNode $contextNode = null, string $axis = 'descendant-or-self::', int $nodeType = XML_ELEMENT_NODE):NodeList{ |
78 | 78 | |
79 | - if(is_string($selectors)){ |
|
79 | + if (is_string($selectors)) { |
|
80 | 80 | $selectors = [trim($selectors)]; |
81 | 81 | } |
82 | 82 | |
83 | - if(!is_array($selectors) || empty($selectors)){ |
|
83 | + if (!is_array($selectors) || empty($selectors)) { |
|
84 | 84 | $selectors = ['*']; |
85 | 85 | } |
86 | 86 | |
87 | 87 | $elements = new NodeList; |
88 | 88 | |
89 | - foreach($selectors as $selector){ |
|
89 | + foreach ($selectors as $selector) { |
|
90 | 90 | |
91 | - foreach($this->querySelectorAll($selector, $contextNode, $axis) as $element){ |
|
91 | + foreach ($this->querySelectorAll($selector, $contextNode, $axis) as $element) { |
|
92 | 92 | |
93 | - if($element->nodeType === $nodeType){ |
|
93 | + if ($element->nodeType === $nodeType) { |
|
94 | 94 | $elements[] = $element; |
95 | 95 | } |
96 | 96 | |
@@ -136,9 +136,9 @@ discard block |
||
136 | 136 | public function removeElementsBySelector($selectors, DOMNode $contextNode = null, string $axis = 'descendant-or-self::'):Document{ |
137 | 137 | $nodes = $this->select($selectors, $contextNode, $axis); |
138 | 138 | |
139 | - if(count($nodes) > 0){ |
|
139 | + if (count($nodes) > 0) { |
|
140 | 140 | /** @var \chillerlan\PrototypeDOM\Element $node */ |
141 | - foreach($nodes as $node){ |
|
141 | + foreach ($nodes as $node) { |
|
142 | 142 | $node->remove(); |
143 | 143 | } |
144 | 144 | |
@@ -155,16 +155,16 @@ discard block |
||
155 | 155 | */ |
156 | 156 | public function _toNodeList($content):NodeList{ |
157 | 157 | |
158 | - if($content instanceof NodeList || $content instanceof DOMNodeList || is_array($content)){ |
|
158 | + if ($content instanceof NodeList || $content instanceof DOMNodeList || is_array($content)) { |
|
159 | 159 | return new NodeList($content); |
160 | 160 | } |
161 | - elseif($content instanceof DOMNode){ |
|
161 | + elseif ($content instanceof DOMNode) { |
|
162 | 162 | return new NodeList([$content]); |
163 | 163 | } |
164 | - elseif(is_string($content)){ |
|
164 | + elseif (is_string($content)) { |
|
165 | 165 | return $this->_loadHTMLFragment($content); |
166 | 166 | } |
167 | - else{ |
|
167 | + else { |
|
168 | 168 | throw new \Exception('invalid content'); // @codeCoverageIgnore |
169 | 169 | } |
170 | 170 | |
@@ -181,15 +181,15 @@ discard block |
||
181 | 181 | public function recursivelyCollect(DOMNode $element, string $property, int $maxLength = -1, int $nodeType = XML_ELEMENT_NODE):NodeList{ |
182 | 182 | $nodes = new NodeList; |
183 | 183 | |
184 | - if(in_array($property, ['parentNode', 'previousSibling', 'nextSibling'])){ |
|
184 | + if (in_array($property, ['parentNode', 'previousSibling', 'nextSibling'])) { |
|
185 | 185 | |
186 | - while($element = $element->{$property}){ |
|
186 | + while ($element = $element->{$property}) { |
|
187 | 187 | |
188 | - if($element->nodeType === $nodeType){ |
|
188 | + if ($element->nodeType === $nodeType) { |
|
189 | 189 | $nodes[] = $element; |
190 | 190 | } |
191 | 191 | |
192 | - if(count($nodes) === $maxLength){ |
|
192 | + if (count($nodes) === $maxLength) { |
|
193 | 193 | break; |
194 | 194 | } |
195 | 195 | |
@@ -209,14 +209,14 @@ discard block |
||
209 | 209 | * |
210 | 210 | * @return \DOMNode|null |
211 | 211 | */ |
212 | - public function _recursivelyFind(DOMNode $element, string $property, string $selector = null, int $index = 0, int $nodeType = XML_ELEMENT_NODE){ |
|
212 | + public function _recursivelyFind(DOMNode $element, string $property, string $selector = null, int $index = 0, int $nodeType = XML_ELEMENT_NODE) { |
|
213 | 213 | |
214 | - if(in_array($property, ['parentNode', 'previousSibling', 'nextSibling'])){ |
|
214 | + if (in_array($property, ['parentNode', 'previousSibling', 'nextSibling'])) { |
|
215 | 215 | |
216 | 216 | /** @var \chillerlan\PrototypeDOM\Element $element */ |
217 | - while($element = $element->{$property}){ |
|
217 | + while ($element = $element->{$property}) { |
|
218 | 218 | |
219 | - if($element->nodeType !== $nodeType || !is_null($selector) && !$element->match($selector) || --$index >= 0){ |
|
219 | + if ($element->nodeType !== $nodeType || !is_null($selector) && !$element->match($selector) || --$index >= 0) { |
|
220 | 220 | continue; |
221 | 221 | } |
222 | 222 | |
@@ -236,9 +236,9 @@ discard block |
||
236 | 236 | */ |
237 | 237 | public function match(DOMNode $element, string $selector):bool{ |
238 | 238 | |
239 | - foreach($this->select($selector) as $match){ |
|
239 | + foreach ($this->select($selector) as $match) { |
|
240 | 240 | |
241 | - if($element->isSameNode($match)){ |
|
241 | + if ($element->isSameNode($match)) { |
|
242 | 242 | return true; |
243 | 243 | } |
244 | 244 | |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | /** @var \chillerlan\PrototypeDOM\Element $element */ |
258 | 258 | $element = $this->createElement($tag); |
259 | 259 | |
260 | - if($attributes){ |
|
260 | + if ($attributes) { |
|
261 | 261 | $element->setAttributes($attributes); |
262 | 262 | } |
263 | 263 |
@@ -157,14 +157,11 @@ |
||
157 | 157 | |
158 | 158 | if($content instanceof NodeList || $content instanceof DOMNodeList || is_array($content)){ |
159 | 159 | return new NodeList($content); |
160 | - } |
|
161 | - elseif($content instanceof DOMNode){ |
|
160 | + } elseif($content instanceof DOMNode){ |
|
162 | 161 | return new NodeList([$content]); |
163 | - } |
|
164 | - elseif(is_string($content)){ |
|
162 | + } elseif(is_string($content)){ |
|
165 | 163 | return $this->_loadHTMLFragment($content); |
166 | - } |
|
167 | - else{ |
|
164 | + } else{ |
|
168 | 165 | throw new \Exception('invalid content'); // @codeCoverageIgnore |
169 | 166 | } |
170 | 167 |
@@ -28,12 +28,12 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @throws \Exception |
30 | 30 | */ |
31 | - public function __construct($content = null){ |
|
31 | + public function __construct($content = null) { |
|
32 | 32 | |
33 | - if($content instanceof NodeList || $content instanceof DOMNodeList){ |
|
33 | + if ($content instanceof NodeList || $content instanceof DOMNodeList) { |
|
34 | 34 | $this->nodelist = iterator_to_array($content); |
35 | 35 | } |
36 | - elseif(is_array($content)){ |
|
36 | + elseif (is_array($content)) { |
|
37 | 37 | $this->nodelist = $content; |
38 | 38 | } |
39 | 39 | /* else{ |
@@ -44,9 +44,9 @@ discard block |
||
44 | 44 | |
45 | 45 | public function match(DOMNode $node):bool{ |
46 | 46 | |
47 | - foreach($this->nodelist as $element){ |
|
47 | + foreach ($this->nodelist as $element) { |
|
48 | 48 | |
49 | - if($element->isSameNode($node)){ |
|
49 | + if ($element->isSameNode($node)) { |
|
50 | 50 | return true; |
51 | 51 | } |
52 | 52 | |
@@ -89,11 +89,11 @@ discard block |
||
89 | 89 | return isset($this->nodelist[$this->key]); |
90 | 90 | } |
91 | 91 | |
92 | - public function next(){ |
|
92 | + public function next() { |
|
93 | 93 | $this->key++; |
94 | 94 | } |
95 | 95 | |
96 | - public function rewind(){ |
|
96 | + public function rewind() { |
|
97 | 97 | $this->key = 0; |
98 | 98 | } |
99 | 99 | |
@@ -102,21 +102,21 @@ discard block |
||
102 | 102 | return isset($this->nodelist[$offset]); |
103 | 103 | } |
104 | 104 | |
105 | - public function offsetGet($offset){ |
|
105 | + public function offsetGet($offset) { |
|
106 | 106 | return $this->nodelist[$offset] ?? null; |
107 | 107 | } |
108 | 108 | |
109 | - public function offsetSet($offset, $value){ |
|
109 | + public function offsetSet($offset, $value) { |
|
110 | 110 | |
111 | - if($this->offsetExists($offset)){ |
|
111 | + if ($this->offsetExists($offset)) { |
|
112 | 112 | $this->nodelist[$offset] = $value; |
113 | 113 | } |
114 | - else{ |
|
114 | + else { |
|
115 | 115 | $this->nodelist[] = $value; |
116 | 116 | } |
117 | 117 | } |
118 | 118 | |
119 | - public function offsetUnset($offset){ |
|
119 | + public function offsetUnset($offset) { |
|
120 | 120 | unset($this->nodelist[$offset]); |
121 | 121 | } |
122 | 122 |
@@ -32,8 +32,7 @@ discard block |
||
32 | 32 | |
33 | 33 | if($content instanceof NodeList || $content instanceof DOMNodeList){ |
34 | 34 | $this->nodelist = iterator_to_array($content); |
35 | - } |
|
36 | - elseif(is_array($content)){ |
|
35 | + } elseif(is_array($content)){ |
|
37 | 36 | $this->nodelist = $content; |
38 | 37 | } |
39 | 38 | /* else{ |
@@ -110,8 +109,7 @@ discard block |
||
110 | 109 | |
111 | 110 | if($this->offsetExists($offset)){ |
112 | 111 | $this->nodelist[$offset] = $value; |
113 | - } |
|
114 | - else{ |
|
112 | + } else{ |
|
115 | 113 | $this->nodelist[] = $value; |
116 | 114 | } |
117 | 115 | } |
@@ -14,7 +14,7 @@ |
||
14 | 14 | |
15 | 15 | use DOMText; |
16 | 16 | |
17 | -class Text extends DOMText{ |
|
17 | +class Text extends DOMText { |
|
18 | 18 | use ManipulationTrait, TraversalTrait; |
19 | 19 | |
20 | 20 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | |
15 | 15 | use DOMElement; |
16 | 16 | |
17 | -class Element extends DOMElement{ |
|
17 | +class Element extends DOMElement { |
|
18 | 18 | use ManipulationTrait, TraversalTrait; |
19 | 19 | |
20 | 20 | /** |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | public function id(string $newID = null):string { |
26 | 26 | $oldID = $this->getAttribute('id'); |
27 | 27 | |
28 | - if(!is_null($newID)){ |
|
28 | + if (!is_null($newID)) { |
|
29 | 29 | $this->setAttribute('id', $newID); |
30 | 30 | } |
31 | 31 | |
@@ -38,14 +38,14 @@ discard block |
||
38 | 38 | public function getClassNames():array{ |
39 | 39 | $currentClassnames = []; |
40 | 40 | |
41 | - if($this->hasAttributes()){ |
|
41 | + if ($this->hasAttributes()) { |
|
42 | 42 | $classnames = explode(' ', trim($this->getAttribute('class'))); |
43 | 43 | |
44 | - if(!empty($classnames)){ |
|
44 | + if (!empty($classnames)) { |
|
45 | 45 | |
46 | - foreach($classnames as $classname){ |
|
46 | + foreach ($classnames as $classname) { |
|
47 | 47 | |
48 | - if(empty($classname)){ |
|
48 | + if (empty($classname)) { |
|
49 | 49 | continue; |
50 | 50 | } |
51 | 51 | |
@@ -76,9 +76,9 @@ discard block |
||
76 | 76 | public function addClassNames(array $classnames):Element{ |
77 | 77 | $currentClassnames = $this->getClassNames(); |
78 | 78 | |
79 | - foreach($classnames as $classname){ |
|
79 | + foreach ($classnames as $classname) { |
|
80 | 80 | |
81 | - if(!in_array($classname, $currentClassnames, true)){ |
|
81 | + if (!in_array($classname, $currentClassnames, true)) { |
|
82 | 82 | array_push($currentClassnames, $classname); |
83 | 83 | } |
84 | 84 | |
@@ -97,12 +97,12 @@ discard block |
||
97 | 97 | public function removeClassNames(array $classnames):Element{ |
98 | 98 | $currentClassnames = $this->getClassNames(); |
99 | 99 | |
100 | - foreach($classnames as $classname){ |
|
100 | + foreach ($classnames as $classname) { |
|
101 | 101 | $keys = array_keys($currentClassnames, $classname); |
102 | 102 | |
103 | - if(!empty($keys)){ |
|
103 | + if (!empty($keys)) { |
|
104 | 104 | |
105 | - foreach($keys as $key){ |
|
105 | + foreach ($keys as $key) { |
|
106 | 106 | unset($currentClassnames[$key]); |
107 | 107 | } |
108 | 108 | |
@@ -151,15 +151,15 @@ discard block |
||
151 | 151 | public function getStyle():array{ |
152 | 152 | $currentStyle = []; |
153 | 153 | |
154 | - if($this->hasAttributes()){ |
|
154 | + if ($this->hasAttributes()) { |
|
155 | 155 | $styles = explode(';', trim($this->getAttribute('style'))); |
156 | 156 | |
157 | - if(!empty($styles)){ |
|
157 | + if (!empty($styles)) { |
|
158 | 158 | |
159 | - foreach($styles as $style){ |
|
159 | + foreach ($styles as $style) { |
|
160 | 160 | $s = explode(':', $style); |
161 | 161 | |
162 | - if(count($s) === 2){ |
|
162 | + if (count($s) === 2) { |
|
163 | 163 | $currentStyle[strtolower(trim($s[0]))] = trim($s[1]); |
164 | 164 | } |
165 | 165 | |
@@ -177,10 +177,10 @@ discard block |
||
177 | 177 | * |
178 | 178 | * @return bool|string |
179 | 179 | */ |
180 | - public function hasStyle(string $property){ |
|
180 | + public function hasStyle(string $property) { |
|
181 | 181 | $currentStyle = $this->getStyle(); |
182 | 182 | |
183 | - if(array_key_exists(strtolower($property), $currentStyle)){ |
|
183 | + if (array_key_exists(strtolower($property), $currentStyle)) { |
|
184 | 184 | return $currentStyle[$property]; |
185 | 185 | } |
186 | 186 | |
@@ -196,11 +196,11 @@ discard block |
||
196 | 196 | public function setStyle(array $style, bool $replace = false):Element{ |
197 | 197 | $currentStyle = $this->getStyle(); |
198 | 198 | |
199 | - if(!$replace){ |
|
199 | + if (!$replace) { |
|
200 | 200 | $style = array_merge($currentStyle, $style); |
201 | 201 | } |
202 | 202 | |
203 | - foreach($style as $property => $value){ |
|
203 | + foreach ($style as $property => $value) { |
|
204 | 204 | $style[$property] = $property.': '.$value.';'; |
205 | 205 | } |
206 | 206 | |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | public function getAttributes():array{ |
216 | 216 | $attributes = []; |
217 | 217 | |
218 | - foreach($this->attributes as $attribute){ |
|
218 | + foreach ($this->attributes as $attribute) { |
|
219 | 219 | $attributes[$attribute->nodeName] = $attribute->nodeValue; |
220 | 220 | } |
221 | 221 | |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | */ |
230 | 230 | public function setAttributes(array $attributes):Element{ |
231 | 231 | |
232 | - foreach($attributes as $name => $value){ |
|
232 | + foreach ($attributes as $name => $value) { |
|
233 | 233 | $this->setAttribute($name, $value); |
234 | 234 | } |
235 | 235 | |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | */ |
244 | 244 | public function removeAttributes(array $attributes):Element{ |
245 | 245 | |
246 | - foreach($attributes as $name){ |
|
246 | + foreach ($attributes as $name) { |
|
247 | 247 | $this->removeAttribute($name); |
248 | 248 | } |
249 | 249 |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * @extends \DOMNode |
19 | 19 | */ |
20 | -trait ManipulationTrait{ |
|
20 | +trait ManipulationTrait { |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * @link http://php.net/manual/class.domnode.php#domnode.props.ownerdocument |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function remove():DOMNode{ |
48 | 48 | |
49 | - if(!$this->parentNode){ |
|
49 | + if (!$this->parentNode) { |
|
50 | 50 | /** @var \chillerlan\PrototypeDOM\Element $this */ |
51 | 51 | return $this; |
52 | 52 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public function replace(DOMNode $newnode):DOMNode{ |
64 | 64 | |
65 | - if(!$this->parentNode){ |
|
65 | + if (!$this->parentNode) { |
|
66 | 66 | /** @var \chillerlan\PrototypeDOM\Element $this */ |
67 | 67 | return $this; |
68 | 68 | } |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | */ |
87 | 87 | public function empty():DOMNode{ |
88 | 88 | |
89 | - while($this->hasChildNodes()){ |
|
89 | + while ($this->hasChildNodes()) { |
|
90 | 90 | $this->firstChild->remove(); |
91 | 91 | } |
92 | 92 | |
@@ -113,10 +113,10 @@ discard block |
||
113 | 113 | public function cleanWhitespace():DOMNode{ |
114 | 114 | $node = $this->firstChild; |
115 | 115 | |
116 | - while($node){ |
|
116 | + while ($node) { |
|
117 | 117 | $nextNode = $node->nextSibling; |
118 | 118 | |
119 | - if($node->nodeType === XML_TEXT_NODE && empty(trim($node->nodeValue))){ |
|
119 | + if ($node->nodeType === XML_TEXT_NODE && empty(trim($node->nodeValue))) { |
|
120 | 120 | $node->remove(); |
121 | 121 | } |
122 | 122 | |
@@ -149,18 +149,18 @@ discard block |
||
149 | 149 | */ |
150 | 150 | public function insert($content):DOMNode{ |
151 | 151 | |
152 | - if(is_array($content)){ |
|
152 | + if (is_array($content)) { |
|
153 | 153 | |
154 | - foreach(['before', 'after', 'top', 'bottom'] as $pos){ |
|
154 | + foreach (['before', 'after', 'top', 'bottom'] as $pos) { |
|
155 | 155 | |
156 | - if(array_key_exists($pos, $content)){ |
|
156 | + if (array_key_exists($pos, $content)) { |
|
157 | 157 | $nodes = $this->ownerDocument->_toNodeList($content[$pos]); |
158 | 158 | |
159 | - if($pos === 'top'){ |
|
159 | + if ($pos === 'top') { |
|
160 | 160 | $nodes->reverse(); |
161 | 161 | } |
162 | 162 | |
163 | - foreach($nodes as $node){ |
|
163 | + foreach ($nodes as $node) { |
|
164 | 164 | call_user_func_array([$this, 'insert_'.$pos], [$node]); |
165 | 165 | } |
166 | 166 | |
@@ -169,8 +169,8 @@ discard block |
||
169 | 169 | } |
170 | 170 | |
171 | 171 | } |
172 | - else{ |
|
173 | - foreach($this->ownerDocument->_toNodeList($content) as $node){ |
|
172 | + else { |
|
173 | + foreach ($this->ownerDocument->_toNodeList($content) as $node) { |
|
174 | 174 | $this->insert_bottom($node); |
175 | 175 | } |
176 | 176 | } |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | */ |
188 | 188 | public function insert_before(DOMNode $node, DOMNode $refNode = null):DOMNode{ |
189 | 189 | |
190 | - if($this->parentNode){ |
|
190 | + if ($this->parentNode) { |
|
191 | 191 | $this->parentNode->insertBefore($this->_importNode($node), $refNode ?? $this); |
192 | 192 | } |
193 | 193 |
@@ -168,8 +168,7 @@ |
||
168 | 168 | |
169 | 169 | } |
170 | 170 | |
171 | - } |
|
172 | - else{ |
|
171 | + } else{ |
|
173 | 172 | foreach($this->ownerDocument->_toNodeList($content) as $node){ |
174 | 173 | $this->insert_bottom($node); |
175 | 174 | } |