@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | |
| 84 | 84 | $condition = with\predicate($condition); |
| 85 | 85 | |
| 86 | - return function (...$arguments) use ($listener, $condition) { |
|
| 86 | + return function(...$arguments) use ($listener, $condition) { |
|
| 87 | 87 | if ($condition(...$arguments)) { |
| 88 | 88 | return (bool)$listener(...$arguments); |
| 89 | 89 | } |
@@ -94,8 +94,8 @@ discard block |
||
| 94 | 94 | |
| 95 | 95 | private function getOnceCallable(callable $listener, $event) : callable |
| 96 | 96 | { |
| 97 | - return $onceListener = function (...$arguments) use (&$onceListener, $event, $listener) { |
|
| 98 | - if(($result = $listener(...$arguments)) !== null) { |
|
| 97 | + return $onceListener = function(...$arguments) use (&$onceListener, $event, $listener) { |
|
| 98 | + if (($result = $listener(...$arguments)) !== null) { |
|
| 99 | 99 | $this->removeListener($event, $onceListener); |
| 100 | 100 | return $result; |
| 101 | 101 | } |
@@ -76,32 +76,32 @@ discard block |
||
| 76 | 76 | |
| 77 | 77 | $this->_parser = $parser; |
| 78 | 78 | |
| 79 | - $this->on('element', function (Error $element) { |
|
| 79 | + $this->on('element', function(Error $element) { |
|
| 80 | 80 | $this->handleError($element); |
| 81 | 81 | }, with\ofType(Error::class)); |
| 82 | 82 | |
| 83 | - $this->_parser->on('parse.begin', function (XmlElement $stream) { |
|
| 83 | + $this->_parser->on('parse.begin', function(XmlElement $stream) { |
|
| 84 | 84 | $this->_stream = $stream; |
| 85 | - $this->emit('stream.open', [ $stream ]); |
|
| 85 | + $this->emit('stream.open', [$stream]); |
|
| 86 | 86 | }, with\all(with\tag('stream'), with\xmlns(self::NAMESPACE_URI))); |
| 87 | 87 | |
| 88 | - $this->_parser->on('parse.end', function (XmlElement $stream) { |
|
| 89 | - $this->emit('stream.close', [ $stream ]); |
|
| 88 | + $this->_parser->on('parse.end', function(XmlElement $stream) { |
|
| 89 | + $this->emit('stream.close', [$stream]); |
|
| 90 | 90 | $this->_stream = null; |
| 91 | 91 | }, with\all(with\tag('stream'), with\xmlns(self::NAMESPACE_URI))); |
| 92 | 92 | |
| 93 | 93 | $this->on('data', [$this->_parser, 'parse']); |
| 94 | - $this->_parser->on('element', function (...$arguments) { |
|
| 94 | + $this->_parser->on('element', function(...$arguments) { |
|
| 95 | 95 | try { |
| 96 | 96 | $this->emit('element', $arguments); |
| 97 | - } catch(\Throwable $error) { |
|
| 98 | - if($this->emit('exception', [ $error ])) { |
|
| 97 | + } catch (\Throwable $error) { |
|
| 98 | + if ($this->emit('exception', [$error])) { |
|
| 99 | 99 | throw $error; |
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | }); |
| 104 | - $this->on('close', function () { $this->_isOpened = false; }); |
|
| 104 | + $this->on('close', function() { $this->_isOpened = false; }); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | */ |
| 114 | 114 | public function write($data) |
| 115 | 115 | { |
| 116 | - $this->emit('send.'.($data instanceof XmlElement ? 'element' : 'text'), [ $data ]); |
|
| 116 | + $this->emit('send.' . ($data instanceof XmlElement ? 'element' : 'text'), [$data]); |
|
| 117 | 117 | |
| 118 | 118 | return parent::write($data); |
| 119 | 119 | } |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | |
| 179 | 179 | private function handleError(Error $element) |
| 180 | 180 | { |
| 181 | - if ($this->emit('stream.error', [ $element ])) { |
|
| 181 | + if ($this->emit('stream.error', [$element])) { |
|
| 182 | 182 | throw new StreamErrorException($element); |
| 183 | 183 | } |
| 184 | 184 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | |
| 55 | 55 | public function getFrom() |
| 56 | 56 | { |
| 57 | - if($this->_from === false) { |
|
| 57 | + if ($this->_from === false) { |
|
| 58 | 58 | $this->_from = $this->hasAttribute('from') ? new Jid($this->_from) : null; |
| 59 | 59 | } |
| 60 | 60 | |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | |
| 64 | 64 | public function getTo() |
| 65 | 65 | { |
| 66 | - if($this->_to === false) { |
|
| 66 | + if ($this->_to === false) { |
|
| 67 | 67 | $this->_to = $this->hasAttribute('to') ? new Jid($this->_to) : null; |
| 68 | 68 | } |
| 69 | 69 | |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | |
| 83 | 83 | public function setFrom($from) |
| 84 | 84 | { |
| 85 | - if($from instanceof Jid) { |
|
| 85 | + if ($from instanceof Jid) { |
|
| 86 | 86 | $this->_from = $from instanceof Jid ? $from : new Jid($from); |
| 87 | 87 | } |
| 88 | 88 | |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | |
| 92 | 92 | public function setTo($to) |
| 93 | 93 | { |
| 94 | - if($to instanceof Jid) { |
|
| 94 | + if ($to instanceof Jid) { |
|
| 95 | 95 | $this->_to = $to instanceof Jid ? $to : new Jid($to); |
| 96 | 96 | } |
| 97 | 97 | |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | { |
| 60 | 60 | parent::setClient($client); |
| 61 | 61 | |
| 62 | - $client->on('features', function (Features $features) { |
|
| 62 | + $client->on('features', function(Features $features) { |
|
| 63 | 63 | return !$this->auth($features); |
| 64 | 64 | }); |
| 65 | 65 | } |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | { |
| 69 | 69 | if (!empty($features->mechanisms)) { |
| 70 | 70 | foreach ($features->mechanisms as $name) { |
| 71 | - if($this->tryMechanism($name)) { |
|
| 71 | + if ($this->tryMechanism($name)) { |
|
| 72 | 72 | return true; |
| 73 | 73 | } |
| 74 | 74 | } |
@@ -112,11 +112,11 @@ discard block |
||
| 112 | 112 | $response = '='; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - $callback = $this->_client->on('element', function (XmlElement $challenge) use ($mechanism) { |
|
| 115 | + $callback = $this->_client->on('element', function(XmlElement $challenge) use ($mechanism) { |
|
| 116 | 116 | $this->handleChallenge($challenge, $mechanism); |
| 117 | 117 | }, with\all(with\tag('challenge'), with\xmlns(self::XMLNS))); |
| 118 | 118 | |
| 119 | - $this->_client->once('element', function (XmlElement $result) use ($callback) { |
|
| 119 | + $this->_client->once('element', function(XmlElement $result) use ($callback) { |
|
| 120 | 120 | $this->_client->removeListener('element', $callback); |
| 121 | 121 | $this->handleAuthResult($result); |
| 122 | 122 | }, with\all(with\any(with\tag('success'), with\tag('failure')), with\xmlns(self::XMLNS))); |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | |
| 127 | 127 | private function mechanismWithoutChallenge(AuthenticationInterface $mechanism) |
| 128 | 128 | { |
| 129 | - $this->_client->once('element', function (XmlElement $result) { |
|
| 129 | + $this->_client->once('element', function(XmlElement $result) { |
|
| 130 | 130 | $this->handleAuthResult($result); |
| 131 | 131 | }, with\all(with\any(with\tag('success'), with\tag('failure')), with\xmlns(self::XMLNS))); |
| 132 | 132 | |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | private function handleAuthResult(XmlElement $result) |
| 145 | 145 | { |
| 146 | 146 | if ($result->localName === 'failure') { |
| 147 | - throw new AuthenticationException('Unable to auth. '.trim($result->innerXml)); |
|
| 147 | + throw new AuthenticationException('Unable to auth. ' . trim($result->innerXml)); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | $this->_client->getLogger()->info('Successfully authorized as {name}.', ['name' => (string)$this->_client->jid]); |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | { |
| 106 | 106 | $this->init($name, $uri); |
| 107 | 107 | $this->append($content); |
| 108 | - foreach($attributes as $name => $value) { |
|
| 108 | + foreach ($attributes as $name => $value) { |
|
| 109 | 109 | $this->setAttribute($name, $value); |
| 110 | 110 | } |
| 111 | 111 | } |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | */ |
| 135 | 135 | public function getInnerXml() |
| 136 | 136 | { |
| 137 | - return implode('', array_map(function ($element) { |
|
| 137 | + return implode('', array_map(function($element) { |
|
| 138 | 138 | if (is_string($element)) { |
| 139 | 139 | return htmlspecialchars($element); |
| 140 | 140 | } elseif ($element instanceof XmlElement) { |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | $attributes = $this->attributes(); |
| 162 | 162 | |
| 163 | 163 | $result = "<{$this->name}"; |
| 164 | - $result .= ' ' . implode(' ', array_map(function ($key, $value) { |
|
| 164 | + $result .= ' ' . implode(' ', array_map(function($key, $value) { |
|
| 165 | 165 | return $key . '="' . htmlspecialchars($value, ENT_QUOTES) . '"'; |
| 166 | 166 | }, array_keys($attributes), array_values($attributes))); |
| 167 | 167 | |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | */ |
| 183 | 183 | public function lookupPrefix(string $uri = null) |
| 184 | 184 | { |
| 185 | - return $this->getNamespaces()[ $uri ] ?? false; |
|
| 185 | + return $this->getNamespaces()[$uri] ?? false; |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -226,12 +226,12 @@ discard block |
||
| 226 | 226 | { |
| 227 | 227 | $attribute = $this->_prefix($attribute, $uri); |
| 228 | 228 | if ($value === null) { |
| 229 | - unset($this->_attributes[ $attribute ]); |
|
| 229 | + unset($this->_attributes[$attribute]); |
|
| 230 | 230 | |
| 231 | 231 | return; |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | - $this->_attributes[ $attribute ] = $value; |
|
| 234 | + $this->_attributes[$attribute] = $value; |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | */ |
| 244 | 244 | public function getAttribute(string $attribute, string $uri = null) |
| 245 | 245 | { |
| 246 | - return $this->_attributes[ $this->_prefix($attribute, $uri) ] ?? false; |
|
| 246 | + return $this->_attributes[$this->_prefix($attribute, $uri)] ?? false; |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | /** |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | */ |
| 257 | 257 | public function hasAttribute(string $attribute, string $uri = null) |
| 258 | 258 | { |
| 259 | - return isset($this->_attributes[ $this->_prefix($attribute, $uri) ]); |
|
| 259 | + return isset($this->_attributes[$this->_prefix($attribute, $uri)]); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | protected function setParent(XmlElement $parent) |
| 276 | 276 | { |
| 277 | 277 | if (!$this->_prefix && ($prefix = $parent->lookupPrefix($this->namespace)) !== false) { |
| 278 | - $this->_namespaces[ $this->namespace ] = $prefix; |
|
| 278 | + $this->_namespaces[$this->namespace] = $prefix; |
|
| 279 | 279 | $this->_prefix = $prefix; |
| 280 | 280 | } |
| 281 | 281 | |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | return false; |
| 299 | 299 | } |
| 300 | 300 | |
| 301 | - if(is_array($element)) { |
|
| 301 | + if (is_array($element)) { |
|
| 302 | 302 | array_walk($element, [$this, 'append']); |
| 303 | 303 | return $element; |
| 304 | 304 | } |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | $prefix = $this->_prefix; |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | - $this->_namespaces[ $uri ] = $prefix; |
|
| 345 | + $this->_namespaces[$uri] = $prefix; |
|
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | public function getName() |
@@ -381,7 +381,7 @@ discard block |
||
| 381 | 381 | */ |
| 382 | 382 | public function element(string $name, string $uri = null, int $index = 0) |
| 383 | 383 | { |
| 384 | - return array_values($this->elements($name, $uri))[ $index ] ?? false; |
|
| 384 | + return array_values($this->elements($name, $uri))[$index] ?? false; |
|
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | /** |
@@ -455,7 +455,7 @@ discard block |
||
| 455 | 455 | private function attributes(): array |
| 456 | 456 | { |
| 457 | 457 | $namespaces = $this->getNamespaces(false); |
| 458 | - $namespaces = array_map(function ($prefix, $uri) { |
|
| 458 | + $namespaces = array_map(function($prefix, $uri) { |
|
| 459 | 459 | return [$prefix ? "xmlns:{$prefix}" : 'xmlns', $uri]; |
| 460 | 460 | }, array_values($namespaces), array_keys($namespaces)); |
| 461 | 461 | |
@@ -29,11 +29,11 @@ |
||
| 29 | 29 | { |
| 30 | 30 | parent::setClient($client); |
| 31 | 31 | |
| 32 | - $client->on('features', function (Features $features) { |
|
| 32 | + $client->on('features', function(Features $features) { |
|
| 33 | 33 | return $this->handleFeatures($features); |
| 34 | 34 | }, null, 10); |
| 35 | 35 | |
| 36 | - $client->on('element', function (XmlElement $element) { |
|
| 36 | + $client->on('element', function(XmlElement $element) { |
|
| 37 | 37 | $this->handleTls($element); |
| 38 | 38 | }, with\xmlns(Features\StartTls::XMLNS)); |
| 39 | 39 | } |
@@ -71,13 +71,13 @@ discard block |
||
| 71 | 71 | xml_parser_set_option($this->_parser, XML_OPTION_SKIP_WHITE, 1); |
| 72 | 72 | xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, 0); |
| 73 | 73 | |
| 74 | - xml_set_element_handler($this->_parser, function ($parser, $name, $attrs) { |
|
| 74 | + xml_set_element_handler($this->_parser, function($parser, $name, $attrs) { |
|
| 75 | 75 | $this->handleElementStart($name, $attrs); |
| 76 | - }, function () { |
|
| 76 | + }, function() { |
|
| 77 | 77 | $this->handleElementEnd(); |
| 78 | 78 | }); |
| 79 | 79 | |
| 80 | - xml_set_character_data_handler($this->_parser, function ($parser, $data) { |
|
| 80 | + xml_set_character_data_handler($this->_parser, function($parser, $data) { |
|
| 81 | 81 | $this->handleTextData($data); |
| 82 | 82 | }); |
| 83 | 83 | |
@@ -111,8 +111,8 @@ discard block |
||
| 111 | 111 | return 'http://www.w3.org/2000/xmlns/'; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - if (isset($namespaces[ $prefix ])) { |
|
| 115 | - return $namespaces[ $prefix ]; |
|
| 114 | + if (isset($namespaces[$prefix])) { |
|
| 115 | + return $namespaces[$prefix]; |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | return !empty($this->_stack) ? end($this->_stack)->lookupUri($prefix) : null; |
@@ -123,10 +123,10 @@ discard block |
||
| 123 | 123 | list($attributes, $namespaces) = $this->_attributes($attrs); |
| 124 | 124 | list($tag, $prefix) = XmlElement::resolve($name); |
| 125 | 125 | |
| 126 | - $uri = $this->_lookup($prefix, $namespaces); |
|
| 126 | + $uri = $this->_lookup($prefix, $namespaces); |
|
| 127 | 127 | |
| 128 | 128 | /** @var XmlElement $element */ |
| 129 | - $element = $this->factory->create($uri, $tag, [ $name, $uri ]); |
|
| 129 | + $element = $this->factory->create($uri, $tag, [$name, $uri]); |
|
| 130 | 130 | |
| 131 | 131 | foreach ($namespaces as $prefix => $uri) { |
| 132 | 132 | $element->setNamespace($uri, $prefix); |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | if (count($this->_stack) > 1) { |
| 146 | 146 | end($this->_stack)->append($element); |
| 147 | 147 | } |
| 148 | - $this->emit('parse.begin', [ $element ]); |
|
| 148 | + $this->emit('parse.begin', [$element]); |
|
| 149 | 149 | |
| 150 | 150 | $this->_stack[] = $element; |
| 151 | 151 | } |
@@ -158,10 +158,10 @@ discard block |
||
| 158 | 158 | |
| 159 | 159 | $element = array_pop($this->_stack); |
| 160 | 160 | if (count($this->_stack) == 1) { |
| 161 | - $this->emit('element', [ $element ]); |
|
| 161 | + $this->emit('element', [$element]); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - $this->emit('parse.end', [ $element ]); |
|
| 164 | + $this->emit('parse.end', [$element]); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | private function handleTextData($data) |
@@ -110,11 +110,11 @@ discard block |
||
| 110 | 110 | |
| 111 | 111 | $this->applyOptions($options); |
| 112 | 112 | |
| 113 | - $this->_connector->on('connect', function (...$arguments) { |
|
| 113 | + $this->_connector->on('connect', function(...$arguments) { |
|
| 114 | 114 | return $this->emit('connect', $arguments); |
| 115 | 115 | }); |
| 116 | 116 | |
| 117 | - $this->on('element', function (Features $element) { |
|
| 117 | + $this->on('element', function(Features $element) { |
|
| 118 | 118 | $this->_features = $element; |
| 119 | 119 | $this->emit('features', [$element]); |
| 120 | 120 | }, Features::class); |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | 'password' => -1 |
| 134 | 134 | ]); |
| 135 | 135 | |
| 136 | - if($options['default-modules']) { |
|
| 136 | + if ($options['default-modules']) { |
|
| 137 | 137 | $options['modules'] = array_merge([ |
| 138 | 138 | TlsEnabler::class => new TlsEnabler(), |
| 139 | 139 | Binding::class => new Binding(), |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | )); |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - $this->_connector->on('connect', function ($stream) { |
|
| 221 | + $this->_connector->on('connect', function($stream) { |
|
| 222 | 222 | $this->handleConnect($stream); |
| 223 | 223 | }); |
| 224 | 224 | } |