@@ -30,18 +30,18 @@ discard block |
||
30 | 30 | { |
31 | 31 | parent::setClient($client); |
32 | 32 | |
33 | - $client->on('features', function (Features $features) { |
|
33 | + $client->on('features', function(Features $features) { |
|
34 | 34 | return !$this->bind($features); |
35 | 35 | }); |
36 | 36 | } |
37 | 37 | |
38 | 38 | public function bind(Features $features) |
39 | 39 | { |
40 | - if($features->has(\Kadet\Xmpp\Utils\filter\element('bind', self::XMLNS))) { |
|
40 | + if ($features->has(\Kadet\Xmpp\Utils\filter\element('bind', self::XMLNS))) { |
|
41 | 41 | $stanza = new Stanza('iq', ['type' => 'set']); |
42 | 42 | $bind = $stanza->append(new XmlElement('bind', self::XMLNS)); |
43 | 43 | |
44 | - if(!$this->_client->jid->isBare()) { |
|
44 | + if (!$this->_client->jid->isBare()) { |
|
45 | 45 | $bind->append(new XmlElement('resource', null, $this->_client->jid->resource)); |
46 | 46 | } |
47 | 47 | |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | |
59 | 59 | public function handleResult(Stanza $stanza) |
60 | 60 | { |
61 | - if($stanza->type === 'result') { |
|
61 | + if ($stanza->type === 'result') { |
|
62 | 62 | $this->_client->bind($stanza->element('bind', self::XMLNS)->element('jid')->innerXml); |
63 | 63 | } |
64 | 64 | } |
@@ -25,8 +25,8 @@ discard block |
||
25 | 25 | |
26 | 26 | function xmlns($uri) |
27 | 27 | { |
28 | - return function ($element) use ($uri) { |
|
29 | - if(!$element instanceof XmlElement) { |
|
28 | + return function($element) use ($uri) { |
|
29 | + if (!$element instanceof XmlElement) { |
|
30 | 30 | return false; |
31 | 31 | } |
32 | 32 | |
@@ -36,8 +36,8 @@ discard block |
||
36 | 36 | |
37 | 37 | function tag($name) |
38 | 38 | { |
39 | - return function ($element) use ($name) { |
|
40 | - if(!$element instanceof XmlElement) { |
|
39 | + return function($element) use ($name) { |
|
40 | + if (!$element instanceof XmlElement) { |
|
41 | 41 | return false; |
42 | 42 | } |
43 | 43 | |
@@ -47,14 +47,14 @@ discard block |
||
47 | 47 | |
48 | 48 | function ofType($class) |
49 | 49 | { |
50 | - return function ($object) use ($class) { |
|
50 | + return function($object) use ($class) { |
|
51 | 51 | return $object instanceof $class; |
52 | 52 | }; |
53 | 53 | } |
54 | 54 | |
55 | 55 | function all(callable ...$functions) |
56 | 56 | { |
57 | - return function (...$args) use ($functions) { |
|
57 | + return function(...$args) use ($functions) { |
|
58 | 58 | foreach ($functions as $function) { |
59 | 59 | if (!$function(...$args)) { |
60 | 60 | return false; |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | |
68 | 68 | function any(callable ...$functions) |
69 | 69 | { |
70 | - return function (...$args) use ($functions) { |
|
70 | + return function(...$args) use ($functions) { |
|
71 | 71 | foreach ($functions as $function) { |
72 | 72 | if ($function(...$args)) { |
73 | 73 | return true; |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | |
92 | 92 | function argument($name, $value) { |
93 | 93 | return function($element) use ($name, $value) { |
94 | - if(!$element instanceof XmlElement) { |
|
94 | + if (!$element instanceof XmlElement) { |
|
95 | 95 | return false; |
96 | 96 | } |
97 | 97 |
@@ -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 | } |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | */ |
131 | 131 | public function getInnerXml() |
132 | 132 | { |
133 | - return implode('', array_map(function ($element) { |
|
133 | + return implode('', array_map(function($element) { |
|
134 | 134 | if (is_string($element)) { |
135 | 135 | return htmlspecialchars($element); |
136 | 136 | } elseif ($element instanceof XmlElement) { |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | $attributes = $this->attributes(); |
158 | 158 | |
159 | 159 | $result = "<{$this->name}"; |
160 | - $result .= ' ' . implode(' ', array_map(function ($key, $value) { |
|
160 | + $result .= ' ' . implode(' ', array_map(function($key, $value) { |
|
161 | 161 | return $key . '="' . htmlspecialchars($value, ENT_QUOTES) . '"'; |
162 | 162 | }, array_keys($attributes), array_values($attributes))); |
163 | 163 | |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | */ |
179 | 179 | public function lookupPrefix(string $uri = null) |
180 | 180 | { |
181 | - return $this->getNamespaces()[ $uri ] ?? false; |
|
181 | + return $this->getNamespaces()[$uri] ?? false; |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
@@ -222,12 +222,12 @@ discard block |
||
222 | 222 | { |
223 | 223 | $attribute = $this->_prefix($attribute, $uri); |
224 | 224 | if ($value === null) { |
225 | - unset($this->_attributes[ $attribute ]); |
|
225 | + unset($this->_attributes[$attribute]); |
|
226 | 226 | |
227 | 227 | return; |
228 | 228 | } |
229 | 229 | |
230 | - $this->_attributes[ $attribute ] = $value; |
|
230 | + $this->_attributes[$attribute] = $value; |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | */ |
240 | 240 | public function getAttribute(string $attribute, string $uri = null) |
241 | 241 | { |
242 | - return $this->_attributes[ $this->_prefix($attribute, $uri) ] ?? false; |
|
242 | + return $this->_attributes[$this->_prefix($attribute, $uri)] ?? false; |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | */ |
253 | 253 | public function hasAttribute(string $attribute, string $uri = null) |
254 | 254 | { |
255 | - return isset($this->_attributes[ $this->_prefix($attribute, $uri) ]); |
|
255 | + return isset($this->_attributes[$this->_prefix($attribute, $uri)]); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | /** |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | protected function setParent(XmlElement $parent) |
272 | 272 | { |
273 | 273 | if (!$this->_prefix && ($prefix = $parent->lookupPrefix($this->namespace)) !== false) { |
274 | - $this->_namespaces[ $this->namespace ] = $prefix; |
|
274 | + $this->_namespaces[$this->namespace] = $prefix; |
|
275 | 275 | $this->_prefix = $prefix; |
276 | 276 | } |
277 | 277 | |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | return false; |
295 | 295 | } |
296 | 296 | |
297 | - if(is_array($element)) { |
|
297 | + if (is_array($element)) { |
|
298 | 298 | array_walk($element, [$this, 'append']); |
299 | 299 | return $element; |
300 | 300 | } |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | $prefix = $this->_prefix; |
339 | 339 | } |
340 | 340 | |
341 | - $this->_namespaces[ $uri ] = $prefix; |
|
341 | + $this->_namespaces[$uri] = $prefix; |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | public function getName() |
@@ -377,7 +377,7 @@ discard block |
||
377 | 377 | */ |
378 | 378 | public function element(string $name, string $uri = null, int $index = 0) |
379 | 379 | { |
380 | - return array_values($this->elements($name, $uri))[ $index ] ?? false; |
|
380 | + return array_values($this->elements($name, $uri))[$index] ?? false; |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | /** |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | private function attributes(): array |
452 | 452 | { |
453 | 453 | $namespaces = $this->getNamespaces(false); |
454 | - $namespaces = array_map(function ($prefix, $uri) { |
|
454 | + $namespaces = array_map(function($prefix, $uri) { |
|
455 | 455 | return [$prefix ? "xmlns:{$prefix}" : 'xmlns', $uri]; |
456 | 456 | }, array_values($namespaces), array_keys($namespaces)); |
457 | 457 |
@@ -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 |
@@ -109,11 +109,11 @@ discard block |
||
109 | 109 | $this->register($module); |
110 | 110 | } |
111 | 111 | |
112 | - $this->_connector->on('connect', function (...$arguments) { |
|
112 | + $this->_connector->on('connect', function(...$arguments) { |
|
113 | 113 | return $this->emit('connect', $arguments); |
114 | 114 | }); |
115 | 115 | |
116 | - $this->on('element', function (Features $element) { |
|
116 | + $this->on('element', function(Features $element) { |
|
117 | 117 | $this->_features = $element; |
118 | 118 | $this->emit('features', [$element]); |
119 | 119 | }, Features::class); |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | { |
160 | 160 | $this->_jid = new Jid($jid); |
161 | 161 | |
162 | - $this->emit('bind', [ $jid ]); |
|
162 | + $this->emit('bind', [$jid]); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | private function handleConnect($stream) |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | )); |
190 | 190 | } |
191 | 191 | |
192 | - $this->_connector->on('connect', function ($stream) { |
|
192 | + $this->_connector->on('connect', function($stream) { |
|
193 | 193 | $this->handleConnect($stream); |
194 | 194 | }); |
195 | 195 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | { |
51 | 51 | parent::setClient($client); |
52 | 52 | |
53 | - $client->on('features', function (Features $features) { |
|
53 | + $client->on('features', function(Features $features) { |
|
54 | 54 | return $this->auth($features); |
55 | 55 | }); |
56 | 56 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | if (!empty($features->mechanisms)) { |
61 | 61 | $sasl = new Sasl(); |
62 | 62 | foreach ($features->mechanisms as $name) { |
63 | - if($this->tryMechanism($sasl, $name)) { |
|
63 | + if ($this->tryMechanism($sasl, $name)) { |
|
64 | 64 | return false; |
65 | 65 | } |
66 | 66 | } |
@@ -91,11 +91,11 @@ discard block |
||
91 | 91 | |
92 | 92 | $auth->append($response); |
93 | 93 | |
94 | - $callback = $this->_client->on('element', function (XmlElement $challenge) use ($mechanism) { |
|
94 | + $callback = $this->_client->on('element', function(XmlElement $challenge) use ($mechanism) { |
|
95 | 95 | $this->handleChallenge($challenge, $mechanism); |
96 | 96 | }, with\all(with\tag('challenge'), with\xmlns(self::XMLNS))); |
97 | 97 | |
98 | - $this->_client->once('element', function (XmlElement $result) use ($callback) { |
|
98 | + $this->_client->once('element', function(XmlElement $result) use ($callback) { |
|
99 | 99 | $this->_client->removeListener('element', $callback); |
100 | 100 | $this->handleAuthResult($result, $callback); |
101 | 101 | }, with\all(with\any(with\tag('success'), with\tag('failure')), with\xmlns(self::XMLNS))); |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | private function handleAuthResult(XmlElement $result, callable $callback) |
122 | 122 | { |
123 | 123 | if ($result->localName === 'failure') { |
124 | - throw new AuthenticationException('Unable to auth. '.trim($result->innerXml)); |
|
124 | + throw new AuthenticationException('Unable to auth. ' . trim($result->innerXml)); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | $this->_client->getLogger()->info('Successfully authorized as {name}.', ['name' => (string)$this->_client->jid]); |