@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | * |
| 262 | 262 | * @param string $attribute Attribute name, optionally with prefix |
| 263 | 263 | * @param string|null $uri XML Namespace URI of attribute, prefix will be automatically looked up |
| 264 | - * @return bool|mixed |
|
| 264 | + * @return string |
|
| 265 | 265 | */ |
| 266 | 266 | public function getAttribute(string $attribute, string $uri = null) |
| 267 | 267 | { |
@@ -483,7 +483,7 @@ discard block |
||
| 483 | 483 | * |
| 484 | 484 | * @param callable|string $predicate Predicate or class name |
| 485 | 485 | * |
| 486 | - * @return XmlElement|false |
|
| 486 | + * @return XmlElement|null |
|
| 487 | 487 | */ |
| 488 | 488 | public function get($predicate) |
| 489 | 489 | { |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | */ |
| 139 | 139 | public function getInnerXml() |
| 140 | 140 | { |
| 141 | - return implode('', array_map(function ($element) { |
|
| 141 | + return implode('', array_map(function($element) { |
|
| 142 | 142 | if (is_string($element)) { |
| 143 | 143 | return htmlspecialchars($element); |
| 144 | 144 | } elseif ($element instanceof XmlElement) { |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | $attributes = $this->attributes(); |
| 184 | 184 | |
| 185 | 185 | $result = "<{$this->fullName}"; |
| 186 | - $result .= ' ' . implode(' ', array_map(function ($key, $value) { |
|
| 186 | + $result .= ' ' . implode(' ', array_map(function($key, $value) { |
|
| 187 | 187 | return $key . '="' . htmlspecialchars($value, ENT_QUOTES) . '"'; |
| 188 | 188 | }, array_keys($attributes), array_values($attributes))); |
| 189 | 189 | |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | */ |
| 205 | 205 | public function lookupPrefix(string $uri = null) |
| 206 | 206 | { |
| 207 | - return $this->getNamespaces()[ $uri ] ?? array_search($uri, XmlParser::$predefined) ?: false; |
|
| 207 | + return $this->getNamespaces()[$uri] ?? array_search($uri, XmlParser::$predefined) ?: false; |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /** |
@@ -248,12 +248,12 @@ discard block |
||
| 248 | 248 | { |
| 249 | 249 | $attribute = $this->_prefix($attribute, $uri); |
| 250 | 250 | if ($value === null) { |
| 251 | - unset($this->_attributes[ $attribute ]); |
|
| 251 | + unset($this->_attributes[$attribute]); |
|
| 252 | 252 | |
| 253 | 253 | return; |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | - $this->_attributes[ $attribute ] = $value; |
|
| 256 | + $this->_attributes[$attribute] = $value; |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | */ |
| 266 | 266 | public function getAttribute(string $attribute, string $uri = null) |
| 267 | 267 | { |
| 268 | - return $this->_attributes[ $this->_prefix($attribute, $uri) ] ?? false; |
|
| 268 | + return $this->_attributes[$this->_prefix($attribute, $uri)] ?? false; |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | /** |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | */ |
| 279 | 279 | public function hasAttribute(string $attribute, string $uri = null) |
| 280 | 280 | { |
| 281 | - return isset($this->_attributes[ $this->_prefix($attribute, $uri) ]); |
|
| 281 | + return isset($this->_attributes[$this->_prefix($attribute, $uri)]); |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | /** |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | */ |
| 288 | 288 | public function getParents() |
| 289 | 289 | { |
| 290 | - return $this->_parent ? array_merge([ $this->_parent ], $this->_parent->getParents()) : []; |
|
| 290 | + return $this->_parent ? array_merge([$this->_parent], $this->_parent->getParents()) : []; |
|
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | /** |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | protected function setParent(XmlElement $parent) |
| 307 | 307 | { |
| 308 | 308 | if (!$this->_prefix && ($prefix = $parent->lookupPrefix($this->namespace)) !== false) { |
| 309 | - $this->_namespaces[ $this->namespace ] = $prefix; |
|
| 309 | + $this->_namespaces[$this->namespace] = $prefix; |
|
| 310 | 310 | $this->_prefix = $prefix; |
| 311 | 311 | } |
| 312 | 312 | |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | return false; |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | - if(is_array($element)) { |
|
| 332 | + if (is_array($element)) { |
|
| 333 | 333 | array_walk($element, [$this, 'appendChild']); |
| 334 | 334 | return $element; |
| 335 | 335 | } |
@@ -339,14 +339,14 @@ discard block |
||
| 339 | 339 | |
| 340 | 340 | public function remove($element) |
| 341 | 341 | { |
| 342 | - if(!$element instanceof \Closure) { |
|
| 342 | + if (!$element instanceof \Closure) { |
|
| 343 | 343 | $element = is_array($element) ? filter\in($element) : filter\same($element); |
| 344 | 344 | } |
| 345 | 345 | $old = $this->_children; |
| 346 | 346 | $this->_children = array_filter($this->_children, not($element)); |
| 347 | 347 | |
| 348 | 348 | foreach (array_diff($old, $this->_children) as $removed) { |
| 349 | - if($removed instanceof XmlElement) { |
|
| 349 | + if ($removed instanceof XmlElement) { |
|
| 350 | 350 | $removed->_parent = null; |
| 351 | 351 | } |
| 352 | 352 | } |
@@ -397,7 +397,7 @@ discard block |
||
| 397 | 397 | $prefix = $this->_prefix; |
| 398 | 398 | } |
| 399 | 399 | |
| 400 | - $this->_namespaces[ $uri ] = $prefix; |
|
| 400 | + $this->_namespaces[$uri] = $prefix; |
|
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | public function getFullName() |
@@ -445,7 +445,7 @@ discard block |
||
| 445 | 445 | */ |
| 446 | 446 | public function element(string $name, string $uri = null, int $index = 0) |
| 447 | 447 | { |
| 448 | - return array_values($this->elements($name, $uri))[ $index ] ?? false; |
|
| 448 | + return array_values($this->elements($name, $uri))[$index] ?? false; |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | /** |
@@ -526,7 +526,7 @@ discard block |
||
| 526 | 526 | private function attributes(): array |
| 527 | 527 | { |
| 528 | 528 | $namespaces = $this->getNamespaces(false); |
| 529 | - $namespaces = array_map(function ($prefix, $uri) { |
|
| 529 | + $namespaces = array_map(function($prefix, $uri) { |
|
| 530 | 530 | return [$prefix ? "xmlns:{$prefix}" : 'xmlns', $uri]; |
| 531 | 531 | }, array_values($namespaces), array_keys($namespaces)); |
| 532 | 532 | |
@@ -76,13 +76,13 @@ discard block |
||
| 76 | 76 | xml_parser_set_option($this->_parser, XML_OPTION_SKIP_WHITE, 1); |
| 77 | 77 | xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, 0); |
| 78 | 78 | |
| 79 | - xml_set_element_handler($this->_parser, function ($parser, $name, $attrs) { |
|
| 79 | + xml_set_element_handler($this->_parser, function($parser, $name, $attrs) { |
|
| 80 | 80 | $this->handleElementStart($name, $attrs); |
| 81 | - }, function () { |
|
| 81 | + }, function() { |
|
| 82 | 82 | $this->handleElementEnd(); |
| 83 | 83 | }); |
| 84 | 84 | |
| 85 | - xml_set_character_data_handler($this->_parser, function ($parser, $data) { |
|
| 85 | + xml_set_character_data_handler($this->_parser, function($parser, $data) { |
|
| 86 | 86 | $this->handleTextData($data); |
| 87 | 87 | }); |
| 88 | 88 | |
@@ -112,12 +112,12 @@ discard block |
||
| 112 | 112 | |
| 113 | 113 | private function _lookup($prefix, $namespaces) |
| 114 | 114 | { |
| 115 | - if(isset(static::$predefined[$prefix])) { |
|
| 115 | + if (isset(static::$predefined[$prefix])) { |
|
| 116 | 116 | return static::$predefined[$prefix]; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - if (isset($namespaces[ $prefix ])) { |
|
| 120 | - return $namespaces[ $prefix ]; |
|
| 119 | + if (isset($namespaces[$prefix])) { |
|
| 120 | + return $namespaces[$prefix]; |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | return !empty($this->_stack) ? end($this->_stack)->lookupUri($prefix) : null; |
@@ -128,10 +128,10 @@ discard block |
||
| 128 | 128 | list($attributes, $namespaces) = $this->_attributes($attrs); |
| 129 | 129 | list($tag, $prefix) = XmlElement::resolve($name); |
| 130 | 130 | |
| 131 | - $uri = $this->_lookup($prefix, $namespaces); |
|
| 131 | + $uri = $this->_lookup($prefix, $namespaces); |
|
| 132 | 132 | |
| 133 | 133 | /** @var XmlElement $element */ |
| 134 | - $element = $this->factory->create($uri, $tag, [ $name, $uri ], $this->_getCollocations()); |
|
| 134 | + $element = $this->factory->create($uri, $tag, [$name, $uri], $this->_getCollocations()); |
|
| 135 | 135 | |
| 136 | 136 | foreach ($namespaces as $prefix => $uri) { |
| 137 | 137 | $element->setNamespace($uri, $prefix); |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | |
| 146 | 146 | private function _getCollocations() |
| 147 | 147 | { |
| 148 | - if(empty($this->_stack)) { |
|
| 148 | + if (empty($this->_stack)) { |
|
| 149 | 149 | return []; |
| 150 | 150 | } |
| 151 | 151 | |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | if (count($this->_stack) > 0) { |
| 165 | 165 | end($this->_stack)->append($element); |
| 166 | 166 | } |
| 167 | - $this->emit('parse.begin', [ $element, count($this->_stack) ]); |
|
| 167 | + $this->emit('parse.begin', [$element, count($this->_stack)]); |
|
| 168 | 168 | |
| 169 | 169 | $this->_stack[] = $element; |
| 170 | 170 | } |
@@ -177,10 +177,10 @@ discard block |
||
| 177 | 177 | |
| 178 | 178 | $element = array_pop($this->_stack); |
| 179 | 179 | if (count($this->_stack) == 1) { |
| 180 | - $this->emit('element', [ $element, count($this->_stack) ]); |
|
| 180 | + $this->emit('element', [$element, count($this->_stack)]); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | - $this->emit('parse.end', [ $element, count($this->_stack) ]); |
|
| 183 | + $this->emit('parse.end', [$element, count($this->_stack)]); |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | private function handleTextData($data) |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | { |
| 42 | 42 | $predicate = $uri instanceof \Closure ? $uri : \Kadet\Xmpp\Utils\filter\same($uri); |
| 43 | 43 | |
| 44 | - return function ($element) use ($predicate) { |
|
| 44 | + return function($element) use ($predicate) { |
|
| 45 | 45 | if (!$element instanceof XmlElement) { |
| 46 | 46 | return false; |
| 47 | 47 | } |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | { |
| 75 | 75 | $predicate = $name instanceof \Closure ? $name : \Kadet\Xmpp\Utils\filter\same($name); |
| 76 | 76 | |
| 77 | - return function ($element) use ($predicate) { |
|
| 77 | + return function($element) use ($predicate) { |
|
| 78 | 78 | if (!$element instanceof XmlElement) { |
| 79 | 79 | return false; |
| 80 | 80 | } |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | { |
| 111 | 111 | $predicate = $value instanceof \Closure ? $value : \Kadet\Xmpp\Utils\filter\equals($value); |
| 112 | 112 | |
| 113 | - return function ($element) use ($name, $predicate, $namespace) { |
|
| 113 | + return function($element) use ($name, $predicate, $namespace) { |
|
| 114 | 114 | if (!$element instanceof XmlElement) { |
| 115 | 115 | return false; |
| 116 | 116 | } |
@@ -49,7 +49,7 @@ |
||
| 49 | 49 | |
| 50 | 50 | private function bodyPredicate($language) { |
| 51 | 51 | $predicate = name('body'); |
| 52 | - if($language !== null) { |
|
| 52 | + if ($language !== null) { |
|
| 53 | 53 | $predicate = all($predicate, attribute('lang', $language, XmlElement::XML)); |
| 54 | 54 | } |
| 55 | 55 | |