@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | |
54 | 54 | public function getFrom() |
55 | 55 | { |
56 | - if((string)$this->_from !== $this->hasAttribute('from')) { |
|
56 | + if ((string)$this->_from !== $this->hasAttribute('from')) { |
|
57 | 57 | $this->_from = $this->hasAttribute('from') ? new Jid($this->_from) : null; |
58 | 58 | } |
59 | 59 | |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | |
63 | 63 | public function getTo() |
64 | 64 | { |
65 | - if((string)$this->_to !== $this->hasAttribute('to')) { |
|
65 | + if ((string)$this->_to !== $this->hasAttribute('to')) { |
|
66 | 66 | $this->_to = $this->hasAttribute('to') ? new Jid($this->_to) : null; |
67 | 67 | } |
68 | 68 | |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | |
87 | 87 | public function setFrom($from) |
88 | 88 | { |
89 | - if($from instanceof Jid) { |
|
89 | + if ($from instanceof Jid) { |
|
90 | 90 | $this->_from = $from instanceof Jid ? $from : new Jid($from); |
91 | 91 | } |
92 | 92 | |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | |
96 | 96 | public function setTo($to) |
97 | 97 | { |
98 | - if($to instanceof Jid) { |
|
98 | + if ($to instanceof Jid) { |
|
99 | 99 | $this->_to = $to instanceof Jid ? $to : new Jid($to); |
100 | 100 | } |
101 | 101 | |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | public static function getXmlCollocations() : array |
132 | 132 | { |
133 | 133 | return [ |
134 | - [ Error::class, 'name' => 'error', 'uri' => 'jabber:client' ], |
|
134 | + [Error::class, 'name' => 'error', 'uri' => 'jabber:client'], |
|
135 | 135 | ]; |
136 | 136 | } |
137 | 137 | } |
@@ -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 ], $this->_getCollocations()); |
|
129 | + $element = $this->factory->create($uri, $tag, [$name, $uri], $this->_getCollocations()); |
|
130 | 130 | |
131 | 131 | foreach ($namespaces as $prefix => $uri) { |
132 | 132 | $element->setNamespace($uri, $prefix); |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | |
141 | 141 | private function _getCollocations() |
142 | 142 | { |
143 | - if(empty($this->_stack)) { |
|
143 | + if (empty($this->_stack)) { |
|
144 | 144 | return []; |
145 | 145 | } |
146 | 146 | |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | if (count($this->_stack) > 0) { |
160 | 160 | end($this->_stack)->append($element); |
161 | 161 | } |
162 | - $this->emit('parse.begin', [ $element, count($this->_stack) ]); |
|
162 | + $this->emit('parse.begin', [$element, count($this->_stack)]); |
|
163 | 163 | |
164 | 164 | $this->_stack[] = $element; |
165 | 165 | } |
@@ -172,10 +172,10 @@ discard block |
||
172 | 172 | |
173 | 173 | $element = array_pop($this->_stack); |
174 | 174 | if (count($this->_stack) == 1) { |
175 | - $this->emit('element', [ $element, count($this->_stack) ]); |
|
175 | + $this->emit('element', [$element, count($this->_stack)]); |
|
176 | 176 | } |
177 | 177 | |
178 | - $this->emit('parse.end', [ $element, count($this->_stack) ]); |
|
178 | + $this->emit('parse.end', [$element, count($this->_stack)]); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | private function handleTextData($data) |
@@ -91,35 +91,35 @@ discard block |
||
91 | 91 | parent::__construct($transport); |
92 | 92 | $this->setParser($parser); |
93 | 93 | |
94 | - $this->on('close', function () { $this->_isOpened = false; }); |
|
95 | - $this->on('element', function (Error $element) { |
|
94 | + $this->on('close', function() { $this->_isOpened = false; }); |
|
95 | + $this->on('element', function(Error $element) { |
|
96 | 96 | $this->handleError($element); |
97 | 97 | }, with\instance(Error::class)); |
98 | 98 | } |
99 | 99 | |
100 | 100 | public function setParser(XmlParser $parser) |
101 | 101 | { |
102 | - if($this->_parser) { |
|
103 | - $this->removeListener('data', [ $this->_parser, 'parse' ]); |
|
102 | + if ($this->_parser) { |
|
103 | + $this->removeListener('data', [$this->_parser, 'parse']); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | $this->_parser = $parser; |
107 | 107 | |
108 | - $this->_parser->on('parse.begin', function (XmlElement $stream) { |
|
108 | + $this->_parser->on('parse.begin', function(XmlElement $stream) { |
|
109 | 109 | $this->_inbound = $stream; |
110 | - $this->emit('stream.open', [ $stream ]); |
|
110 | + $this->emit('stream.open', [$stream]); |
|
111 | 111 | }, with\argument(1, with\equals(0))); |
112 | 112 | |
113 | - $this->_parser->on('parse.end', function (XmlElement $stream) { |
|
114 | - $this->emit('stream.close', [ $stream ]); |
|
113 | + $this->_parser->on('parse.end', function(XmlElement $stream) { |
|
114 | + $this->emit('stream.close', [$stream]); |
|
115 | 115 | $this->_inbound = null; |
116 | 116 | }, with\argument(1, with\equals(0))); |
117 | 117 | |
118 | - $this->_parser->on('element', function (...$arguments) { |
|
118 | + $this->_parser->on('element', function(...$arguments) { |
|
119 | 119 | $this->emit('element', $arguments); |
120 | 120 | }); |
121 | 121 | |
122 | - $this->on('data', [ $this->_parser, 'parse' ]); |
|
122 | + $this->on('data', [$this->_parser, 'parse']); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -130,11 +130,11 @@ discard block |
||
130 | 130 | */ |
131 | 131 | public function write($data) |
132 | 132 | { |
133 | - if($data instanceof XmlElement) { |
|
133 | + if ($data instanceof XmlElement) { |
|
134 | 134 | $this->_outbound->append($data); |
135 | 135 | } |
136 | 136 | |
137 | - $this->emit('send.'.($data instanceof XmlElement ? 'element' : 'text'), [ $data ]); |
|
137 | + $this->emit('send.' . ($data instanceof XmlElement ? 'element' : 'text'), [$data]); |
|
138 | 138 | |
139 | 139 | return parent::write($data); |
140 | 140 | } |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | |
196 | 196 | private function handleError(Error $element) |
197 | 197 | { |
198 | - if ($this->emit('stream.error', [ $element ])) { |
|
198 | + if ($this->emit('stream.error', [$element])) { |
|
199 | 199 | throw new StreamErrorException($element); |
200 | 200 | } |
201 | 201 |
@@ -258,7 +258,7 @@ |
||
258 | 258 | * |
259 | 259 | * @param string $attribute Attribute name, optionally with prefix |
260 | 260 | * @param string|null $uri XML Namespace URI of attribute, prefix will be automatically looked up |
261 | - * @return bool|mixed |
|
261 | + * @return string |
|
262 | 262 | */ |
263 | 263 | public function getAttribute(string $attribute, string $uri = null) |
264 | 264 | { |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | */ |
137 | 137 | public function getInnerXml() |
138 | 138 | { |
139 | - return implode('', array_map(function ($element) { |
|
139 | + return implode('', array_map(function($element) { |
|
140 | 140 | if (is_string($element)) { |
141 | 141 | return htmlspecialchars($element); |
142 | 142 | } elseif ($element instanceof XmlElement) { |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | $attributes = $this->attributes(); |
182 | 182 | |
183 | 183 | $result = "<{$this->fullName}"; |
184 | - $result .= ' ' . implode(' ', array_map(function ($key, $value) { |
|
184 | + $result .= ' ' . implode(' ', array_map(function($key, $value) { |
|
185 | 185 | return $key . '="' . htmlspecialchars($value, ENT_QUOTES) . '"'; |
186 | 186 | }, array_keys($attributes), array_values($attributes))); |
187 | 187 | |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | */ |
203 | 203 | public function lookupPrefix(string $uri = null) |
204 | 204 | { |
205 | - return $this->getNamespaces()[ $uri ] ?? false; |
|
205 | + return $this->getNamespaces()[$uri] ?? false; |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
@@ -246,12 +246,12 @@ discard block |
||
246 | 246 | { |
247 | 247 | $attribute = $this->_prefix($attribute, $uri); |
248 | 248 | if ($value === null) { |
249 | - unset($this->_attributes[ $attribute ]); |
|
249 | + unset($this->_attributes[$attribute]); |
|
250 | 250 | |
251 | 251 | return; |
252 | 252 | } |
253 | 253 | |
254 | - $this->_attributes[ $attribute ] = $value; |
|
254 | + $this->_attributes[$attribute] = $value; |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | /** |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | */ |
264 | 264 | public function getAttribute(string $attribute, string $uri = null) |
265 | 265 | { |
266 | - return $this->_attributes[ $this->_prefix($attribute, $uri) ] ?? false; |
|
266 | + return $this->_attributes[$this->_prefix($attribute, $uri)] ?? false; |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | /** |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | */ |
277 | 277 | public function hasAttribute(string $attribute, string $uri = null) |
278 | 278 | { |
279 | - return isset($this->_attributes[ $this->_prefix($attribute, $uri) ]); |
|
279 | + return isset($this->_attributes[$this->_prefix($attribute, $uri)]); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | /** |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | */ |
286 | 286 | public function getParents() |
287 | 287 | { |
288 | - return $this->_parent ? array_merge([ $this->_parent ], $this->_parent->getParents()) : []; |
|
288 | + return $this->_parent ? array_merge([$this->_parent], $this->_parent->getParents()) : []; |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | /** |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | protected function setParent(XmlElement $parent) |
305 | 305 | { |
306 | 306 | if (!$this->_prefix && ($prefix = $parent->lookupPrefix($this->namespace)) !== false) { |
307 | - $this->_namespaces[ $this->namespace ] = $prefix; |
|
307 | + $this->_namespaces[$this->namespace] = $prefix; |
|
308 | 308 | $this->_prefix = $prefix; |
309 | 309 | } |
310 | 310 | |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | return false; |
328 | 328 | } |
329 | 329 | |
330 | - if(is_array($element)) { |
|
330 | + if (is_array($element)) { |
|
331 | 331 | array_walk($element, [$this, 'appendChild']); |
332 | 332 | return $element; |
333 | 333 | } |
@@ -337,14 +337,14 @@ discard block |
||
337 | 337 | |
338 | 338 | public function remove($element) |
339 | 339 | { |
340 | - if(!$element instanceof \Closure) { |
|
340 | + if (!$element instanceof \Closure) { |
|
341 | 341 | $element = is_array($element) ? filter\in($element) : filter\same($element); |
342 | 342 | } |
343 | 343 | $old = $this->_children; |
344 | 344 | $this->_children = array_filter($this->_children, not($element)); |
345 | 345 | |
346 | 346 | foreach (array_diff($old, $this->_children) as $removed) { |
347 | - if($removed instanceof XmlElement) { |
|
347 | + if ($removed instanceof XmlElement) { |
|
348 | 348 | $removed->_parent = null; |
349 | 349 | } |
350 | 350 | } |
@@ -395,7 +395,7 @@ discard block |
||
395 | 395 | $prefix = $this->_prefix; |
396 | 396 | } |
397 | 397 | |
398 | - $this->_namespaces[ $uri ] = $prefix; |
|
398 | + $this->_namespaces[$uri] = $prefix; |
|
399 | 399 | } |
400 | 400 | |
401 | 401 | public function getFullName() |
@@ -443,7 +443,7 @@ discard block |
||
443 | 443 | */ |
444 | 444 | public function element(string $name, string $uri = null, int $index = 0) |
445 | 445 | { |
446 | - return array_values($this->elements($name, $uri))[ $index ] ?? false; |
|
446 | + return array_values($this->elements($name, $uri))[$index] ?? false; |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /** |
@@ -524,7 +524,7 @@ discard block |
||
524 | 524 | private function attributes(): array |
525 | 525 | { |
526 | 526 | $namespaces = $this->getNamespaces(false); |
527 | - $namespaces = array_map(function ($prefix, $uri) { |
|
527 | + $namespaces = array_map(function($prefix, $uri) { |
|
528 | 528 | return [$prefix ? "xmlns:{$prefix}" : 'xmlns', $uri]; |
529 | 529 | }, array_values($namespaces), array_keys($namespaces)); |
530 | 530 |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | } |
34 | 34 | |
35 | 35 | foreach ($lookup['<predicate>'] as list($class, $predicate)) { |
36 | - if($predicate($tag, $namespace)) { |
|
36 | + if ($predicate($tag, $namespace)) { |
|
37 | 37 | return $class; |
38 | 38 | } |
39 | 39 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | { |
65 | 65 | $result = ['<predicate>' => []]; |
66 | 66 | foreach ($dictionary as $element) { |
67 | - if($element['name'] instanceof \Closure || $element['uri'] instanceof \Closure) { |
|
67 | + if ($element['name'] instanceof \Closure || $element['uri'] instanceof \Closure) { |
|
68 | 68 | $result['<predicate>'][] = [$element[0], \Kadet\Xmpp\Utils\filter\consecutive( |
69 | 69 | \Kadet\Xmpp\Utils\filter\predicate($element['name']), |
70 | 70 | \Kadet\Xmpp\Utils\filter\predicate($element['uri']) |
@@ -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 Stanza('iq', ['attributes' => ['type' => 'set']]); |
43 | 43 | $bind = $stanza->append(new XmlElement('bind', self::XMLNS)); |
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(Stanza $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 |
@@ -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 | } |
@@ -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]); |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | |
49 | 49 | protected function appendChild($element) |
50 | 50 | { |
51 | - if(count($this->children) > 0) { |
|
51 | + if (count($this->children) > 0) { |
|
52 | 52 | throw new \RuntimeException('Iq stanzas cannot have more than one child.'); |
53 | 53 | } |
54 | 54 | |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | public static function getXmlCollocations() : array |
78 | 78 | { |
79 | 79 | return array_merge( |
80 | - [[ Query::class, 'name' => pass(), 'uri' => pass() ]], |
|
80 | + [[Query::class, 'name' => pass(), 'uri' => pass()]], |
|
81 | 81 | parent::getXmlCollocations() |
82 | 82 | ); |
83 | 83 | } |
@@ -19,7 +19,6 @@ |
||
19 | 19 | use Kadet\Xmpp\Jid; |
20 | 20 | use Kadet\Xmpp\Stanza\Iq\Query; |
21 | 21 | use function Kadet\Xmpp\Utils\filter\pass; |
22 | -use Kadet\Xmpp\Xml\XmlElement; |
|
23 | 22 | |
24 | 23 | /** |
25 | 24 | * Represents IQ Stanza |