@@ -31,18 +31,18 @@ discard block |
||
31 | 31 | { |
32 | 32 | parent::setClient($client); |
33 | 33 | |
34 | - $client->on('features', function (Features $features) { |
|
34 | + $client->on('features', function(Features $features) { |
|
35 | 35 | return !$this->bind($features); |
36 | 36 | }); |
37 | 37 | } |
38 | 38 | |
39 | 39 | public function bind(Features $features) |
40 | 40 | { |
41 | - if($features->has(with\element('bind', self::XMLNS))) { |
|
41 | + if ($features->has(with\element('bind', self::XMLNS))) { |
|
42 | 42 | $stanza = new Iq('set'); |
43 | 43 | $bind = $stanza->append(new Iq\Query(self::XMLNS, 'bind')); |
44 | 44 | |
45 | - if(!$this->_client->jid->isBare()) { |
|
45 | + if (!$this->_client->jid->isBare()) { |
|
46 | 46 | $bind->append(new XmlElement('resource', null, ['content' => $this->_client->jid->resource])); |
47 | 47 | } |
48 | 48 | |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | |
60 | 60 | public function handleResult(Iq $stanza) |
61 | 61 | { |
62 | - if($stanza->type === 'error') { |
|
62 | + if ($stanza->type === 'error') { |
|
63 | 63 | throw BindingException::fromError($this->_client->jid, $stanza->error); |
64 | 64 | } |
65 | 65 |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | */ |
56 | 56 | public function enable() |
57 | 57 | { |
58 | - if($this->_interval) { |
|
58 | + if ($this->_interval) { |
|
59 | 59 | $this->_timer = $this->_client->connector->getLoop()->addPeriodicTimer($this->_interval, function() { |
60 | 60 | $this->keepAlive(); |
61 | 61 | }); |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | */ |
68 | 68 | public function disable() |
69 | 69 | { |
70 | - if($this->_timer) { |
|
70 | + if ($this->_timer) { |
|
71 | 71 | $this->_timer->cancel(); |
72 | 72 | } |
73 | 73 |
@@ -38,7 +38,7 @@ |
||
38 | 38 | |
39 | 39 | private function handleSubscriptionRequest(Presence $presence) |
40 | 40 | { |
41 | - $this->emit('request', [ $presence ]); |
|
41 | + $this->emit('request', [$presence]); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -26,11 +26,11 @@ |
||
26 | 26 | { |
27 | 27 | public function init() |
28 | 28 | { |
29 | - $this->_client->on('features', function (Features $features) { |
|
29 | + $this->_client->on('features', function(Features $features) { |
|
30 | 30 | return !$this->startTls($features); |
31 | 31 | }, null, 10); |
32 | 32 | |
33 | - $this->_client->on('element', function (XmlElement $element) { |
|
33 | + $this->_client->on('element', function(XmlElement $element) { |
|
34 | 34 | return $this->handleTls($element); |
35 | 35 | }, with\element\xmlns(Features\StartTls::XMLNS)); |
36 | 36 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | { |
65 | 65 | parent::setClient($client); |
66 | 66 | |
67 | - $client->on('features', function (Features $features) { |
|
67 | + $client->on('features', function(Features $features) { |
|
68 | 68 | return !$this->auth($features); |
69 | 69 | }); |
70 | 70 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | { |
74 | 74 | if (!empty($features->mechanisms)) { |
75 | 75 | foreach ($features->mechanisms as $name) { |
76 | - if($this->tryMechanism($name)) { |
|
76 | + if ($this->tryMechanism($name)) { |
|
77 | 77 | return true; |
78 | 78 | } |
79 | 79 | } |
@@ -117,11 +117,11 @@ discard block |
||
117 | 117 | $response = ''; |
118 | 118 | } |
119 | 119 | |
120 | - $callback = $this->_client->on('element', function (XmlElement $challenge) use ($mechanism) { |
|
120 | + $callback = $this->_client->on('element', function(XmlElement $challenge) use ($mechanism) { |
|
121 | 121 | $this->handleChallenge($challenge, $mechanism); |
122 | 122 | }, with\element('challenge', self::XMLNS)); |
123 | 123 | |
124 | - $this->_client->once('element', function (XmlElement $result) use ($callback) { |
|
124 | + $this->_client->once('element', function(XmlElement $result) use ($callback) { |
|
125 | 125 | $this->_client->removeListener('element', $callback); |
126 | 126 | $this->handleAuthResult($result); |
127 | 127 | }, $this->_resultPredicate()); |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | |
132 | 132 | private function mechanismWithoutChallenge(AuthenticationInterface $mechanism) |
133 | 133 | { |
134 | - $this->_client->once('element', function (XmlElement $result) { |
|
134 | + $this->_client->once('element', function(XmlElement $result) { |
|
135 | 135 | $this->handleAuthResult($result); |
136 | 136 | }, $this->_resultPredicate()); |
137 | 137 | |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | { |
151 | 151 | // todo: handle different scenarios |
152 | 152 | if ($result->localName === 'failure') { |
153 | - throw new AuthenticationException('Unable to auth. '.trim($result->innerXml)); |
|
153 | + throw new AuthenticationException('Unable to auth. ' . trim($result->innerXml)); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | $this->_client->getLogger()->info('Successfully authorized as {name}.', ['name' => (string)$this->_client->jid]); |
@@ -20,7 +20,7 @@ |
||
20 | 20 | { |
21 | 21 | public static function available() { |
22 | 22 | static $reflection = null; |
23 | - if(!$reflection) { |
|
23 | + if (!$reflection) { |
|
24 | 24 | $reflection = new \ReflectionClass(static::class); |
25 | 25 | } |
26 | 26 |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function setShow(string $show = 'available') |
70 | 70 | { |
71 | - if(!Show::valid($show)) { |
|
71 | + if (!Show::valid($show)) { |
|
72 | 72 | throw new InvalidArgumentException(format('$show must be one of: {possible}. {show} given.', [ |
73 | 73 | 'possible' => implode(', ', Show::available()), |
74 | 74 | 'show' => $show |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | } |
77 | 77 | |
78 | 78 | $predicate = filter\element('show', 'jabber:client'); |
79 | - if(in_array($show, ['available', 'unavailable'])) { |
|
79 | + if (in_array($show, ['available', 'unavailable'])) { |
|
80 | 80 | $this->remove($predicate); |
81 | 81 | $this->type = $show; |
82 | 82 | return; |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | public function setStatus(string $status = null) |
99 | 99 | { |
100 | 100 | $predicate = filter\element('status', 'jabber:client'); |
101 | - if($status === null) { |
|
101 | + if ($status === null) { |
|
102 | 102 | $this->remove($predicate); |
103 | 103 | return; |
104 | 104 | } |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | public function setPriority(int $priority = null) |
115 | 115 | { |
116 | 116 | $predicate = filter\element('status', 'jabber:client'); |
117 | - if(!$priority) { |
|
117 | + if (!$priority) { |
|
118 | 118 | $this->remove($predicate); |
119 | 119 | } |
120 | 120 |
@@ -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) |
@@ -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 |