@@ -88,18 +88,18 @@ discard block |
||
| 88 | 88 | |
| 89 | 89 | public function xml($clean = true): string |
| 90 | 90 | { |
| 91 | - if($this->namespace && $this->_prefix === null) { |
|
| 91 | + if ($this->namespace && $this->_prefix === null) { |
|
| 92 | 92 | $this->_prefix = $this->lookupPrefix($this->namespace); |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | $attributes = $this->attributes(); |
| 96 | 96 | |
| 97 | 97 | $result = "<{$this->name}"; |
| 98 | - $result .= ' '.implode(' ', array_map(function($key, $value) { |
|
| 99 | - return $key.'="'.htmlspecialchars($value, ENT_QUOTES).'"'; |
|
| 98 | + $result .= ' ' . implode(' ', array_map(function($key, $value) { |
|
| 99 | + return $key . '="' . htmlspecialchars($value, ENT_QUOTES) . '"'; |
|
| 100 | 100 | }, array_keys($attributes), array_values($attributes))); |
| 101 | 101 | |
| 102 | - if(!empty($this->_children)) { |
|
| 102 | + if (!empty($this->_children)) { |
|
| 103 | 103 | $result .= ">{$this->innerXml}</{$this->name}>"; |
| 104 | 104 | } else { |
| 105 | 105 | $result .= "/>"; |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | public function getInnerXml() |
| 112 | 112 | { |
| 113 | 113 | return implode('', array_map(function($element) { |
| 114 | - if(is_string($element)) { |
|
| 114 | + if (is_string($element)) { |
|
| 115 | 115 | return htmlspecialchars($element); |
| 116 | 116 | } elseif ($element instanceof XmlElement) { |
| 117 | 117 | return $element->xml(false); |
@@ -123,12 +123,12 @@ discard block |
||
| 123 | 123 | |
| 124 | 124 | public function setAttribute(string $attribute, $value, string $uri = null) |
| 125 | 125 | { |
| 126 | - if($uri === 'http://www.w3.org/2000/xmlns/') { |
|
| 126 | + if ($uri === 'http://www.w3.org/2000/xmlns/') { |
|
| 127 | 127 | $this->setNamespace($value, $attribute); |
| 128 | 128 | return; |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - if($uri !== null) { |
|
| 131 | + if ($uri !== null) { |
|
| 132 | 132 | $attribute = $this->_prefix($attribute, $uri); |
| 133 | 133 | } |
| 134 | 134 | |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | |
| 138 | 138 | public function getAttribute(string $attribute, string $uri = null) |
| 139 | 139 | { |
| 140 | - if($uri !== null) { |
|
| 140 | + if ($uri !== null) { |
|
| 141 | 141 | $attribute = $this->_prefix($attribute, $uri); |
| 142 | 142 | } |
| 143 | 143 | |
@@ -154,11 +154,11 @@ discard block |
||
| 154 | 154 | */ |
| 155 | 155 | public function getNamespaces($parent = true): array |
| 156 | 156 | { |
| 157 | - if(!$this->_parent) { |
|
| 157 | + if (!$this->_parent) { |
|
| 158 | 158 | return $this->_namespaces; |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - if($parent) { |
|
| 161 | + if ($parent) { |
|
| 162 | 162 | return array_merge($this->_namespaces, $this->_parent->getNamespaces()); |
| 163 | 163 | } else { |
| 164 | 164 | return array_diff_assoc($this->_namespaces, $this->_parent->getNamespaces()); |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | { |
| 170 | 170 | $namespaces = $this->getNamespaces(false); |
| 171 | 171 | $namespaces = array_map(function($prefix, $uri) { |
| 172 | - return [ $prefix ? "xmlns:{$prefix}" : 'xmlns', $uri ]; |
|
| 172 | + return [$prefix ? "xmlns:{$prefix}" : 'xmlns', $uri]; |
|
| 173 | 173 | }, array_values($namespaces), array_keys($namespaces)); |
| 174 | 174 | |
| 175 | 175 | return array_merge( |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | */ |
| 195 | 195 | public function setNamespace(string $uri, $prefix = false) |
| 196 | 196 | { |
| 197 | - if($prefix === false) { |
|
| 197 | + if ($prefix === false) { |
|
| 198 | 198 | $prefix = $this->_prefix; |
| 199 | 199 | } |
| 200 | 200 | |
@@ -213,15 +213,15 @@ discard block |
||
| 213 | 213 | |
| 214 | 214 | public function append($element) |
| 215 | 215 | { |
| 216 | - if(!is_string($element) && !$element instanceof XmlElement) { |
|
| 216 | + if (!is_string($element) && !$element instanceof XmlElement) { |
|
| 217 | 217 | throw new InvalidArgumentException(helper\format('$element should be either string or object of {class} class, {type} given', [ |
| 218 | 218 | 'class' => XmlElement::class, |
| 219 | 219 | 'type' => helper\typeof($element) |
| 220 | 220 | ])); |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - if($element instanceof XmlElement) { |
|
| 224 | - $element->parent = $this; |
|
| 223 | + if ($element instanceof XmlElement) { |
|
| 224 | + $element->parent = $this; |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | return $this->_children[] = $element; |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | |
| 230 | 230 | public function getName() |
| 231 | 231 | { |
| 232 | - return ($this->_prefix ? $this->prefix.':' : null).$this->localName; |
|
| 232 | + return ($this->_prefix ? $this->prefix . ':' : null) . $this->localName; |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | public function getPrefix() |
@@ -244,17 +244,17 @@ discard block |
||
| 244 | 244 | |
| 245 | 245 | protected function setParent(XmlElement $parent) |
| 246 | 246 | { |
| 247 | - if(!$this->_prefix && ($prefix = $parent->lookupPrefix($this->namespace)) !== false) { |
|
| 247 | + if (!$this->_prefix && ($prefix = $parent->lookupPrefix($this->namespace)) !== false) { |
|
| 248 | 248 | $this->_namespaces[$this->namespace] = $prefix; |
| 249 | 249 | $this->_prefix = $prefix; |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | $this->_parent = $parent; |
| 253 | - if($this->namespace === false) { |
|
| 253 | + if ($this->namespace === false) { |
|
| 254 | 254 | $this->namespace = $parent->namespace; |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - if(!$this->_prefix) { |
|
| 257 | + if (!$this->_prefix) { |
|
| 258 | 258 | $this->_prefix = $this->lookupPrefix($this->namespace); |
| 259 | 259 | } |
| 260 | 260 | } |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | public function elements($name, $uri = null) : array |
| 271 | 271 | { |
| 272 | 272 | $predicate = filter\tag($name); |
| 273 | - if($uri !== null) { |
|
| 273 | + if ($uri !== null) { |
|
| 274 | 274 | $predicate = filter\all($predicate, filter\xmlns($uri)); |
| 275 | 275 | } |
| 276 | 276 | |