@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | /** |
56 | 56 | * Sends subscription removal request presence to server. |
57 | 57 | * |
58 | - * @param Jid|string $jid |
|
58 | + * @param Jid $jid |
|
59 | 59 | * @return \React\Promise\ExtendedPromiseInterface |
60 | 60 | */ |
61 | 61 | public function unsubscribe(Jid $jid) |
@@ -74,6 +74,9 @@ discard block |
||
74 | 74 | return $this->_client->send($this->presence('unsubscribed', $jid)); |
75 | 75 | } |
76 | 76 | |
77 | + /** |
|
78 | + * @param string $type |
|
79 | + */ |
|
77 | 80 | private function presence($type, $jid) |
78 | 81 | { |
79 | 82 | $jid = $jid instanceof Jid ? $jid : new Jid($jid); |
@@ -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 | /** |
@@ -20,7 +20,6 @@ |
||
20 | 20 | use Kadet\Xmpp\Stream\Features; |
21 | 21 | use Kadet\Xmpp\Utils\filter as with; |
22 | 22 | use Kadet\Xmpp\Xml\XmlElement; |
23 | -use Kadet\Xmpp\XmppClient; |
|
24 | 23 | |
25 | 24 | class TlsEnabler extends Component |
26 | 25 | { |
@@ -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 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function setShow(string $show = 'available') |
71 | 71 | { |
72 | - if(!in_array($show, self::POSSIBLE_SHOW)) { |
|
72 | + if (!in_array($show, self::POSSIBLE_SHOW)) { |
|
73 | 73 | throw new InvalidArgumentException(format('$show must be one of: {possible}. {show} given.', [ |
74 | 74 | 'possible' => implode(',', self::POSSIBLE_SHOW), |
75 | 75 | 'show' => $show |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | } |
78 | 78 | |
79 | 79 | $predicate = filter\element('show', 'jabber:client'); |
80 | - if(in_array($show, ['available', 'unavailable'])) { |
|
80 | + if (in_array($show, ['available', 'unavailable'])) { |
|
81 | 81 | $this->remove($predicate); |
82 | 82 | $this->type = $show; |
83 | 83 | return; |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | public function setStatus(string $status = null) |
100 | 100 | { |
101 | 101 | $predicate = filter\element('status', 'jabber:client'); |
102 | - if($status === null) { |
|
102 | + if ($status === null) { |
|
103 | 103 | $this->remove($predicate); |
104 | 104 | return; |
105 | 105 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | public function setPriority(int $priority = null) |
116 | 116 | { |
117 | 117 | $predicate = filter\element('status', 'jabber:client'); |
118 | - if(!$priority) { |
|
118 | + if (!$priority) { |
|
119 | 119 | $this->remove($predicate); |
120 | 120 | } |
121 | 121 |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | */ |
35 | 35 | function equals($value) : \Closure |
36 | 36 | { |
37 | - return function ($argument) use ($value) { |
|
37 | + return function($argument) use ($value) { |
|
38 | 38 | return $argument == $value; |
39 | 39 | }; |
40 | 40 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | */ |
56 | 56 | function same($value) : \Closure |
57 | 57 | { |
58 | - return function ($argument) use ($value) { |
|
58 | + return function($argument) use ($value) { |
|
59 | 59 | return $argument === $value; |
60 | 60 | }; |
61 | 61 | } |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | */ |
78 | 78 | function instance($expected) : \Closure |
79 | 79 | { |
80 | - return function ($object) use ($expected) { |
|
80 | + return function($object) use ($expected) { |
|
81 | 81 | return $expected instanceof \Closure ? $expected(get_class($object)) : $object instanceof $expected; |
82 | 82 | }; |
83 | 83 | } |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | */ |
104 | 104 | function matches($regex, ...$options) : \Closure |
105 | 105 | { |
106 | - return function ($value) use ($regex, $options) { |
|
106 | + return function($value) use ($regex, $options) { |
|
107 | 107 | return preg_match($regex, $value, $null, ...$options) > 0; |
108 | 108 | }; |
109 | 109 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | * @return \Closure |
123 | 123 | */ |
124 | 124 | function in(...$options) { |
125 | - return function ($value) use ($options) { |
|
125 | + return function($value) use ($options) { |
|
126 | 126 | return in_array($value, $options); |
127 | 127 | }; |
128 | 128 | } |
@@ -142,10 +142,10 @@ discard block |
||
142 | 142 | */ |
143 | 143 | function contains($value) |
144 | 144 | { |
145 | - if($value instanceof \Closure) { |
|
146 | - return function (array $array) use ($value) { |
|
145 | + if ($value instanceof \Closure) { |
|
146 | + return function(array $array) use ($value) { |
|
147 | 147 | foreach ($array as $item) { |
148 | - if($value($item)) { |
|
148 | + if ($value($item)) { |
|
149 | 149 | return true; |
150 | 150 | } |
151 | 151 | } |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | }; |
155 | 155 | } |
156 | 156 | |
157 | - return function (array $array) use ($value) { |
|
157 | + return function(array $array) use ($value) { |
|
158 | 158 | return array_search($value, $array) !== false; |
159 | 159 | }; |
160 | 160 | } |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | */ |
175 | 175 | function has($key) |
176 | 176 | { |
177 | - return function (array $array) use ($key) { |
|
177 | + return function(array $array) use ($key) { |
|
178 | 178 | return (contains($key))(array_keys($array)); |
179 | 179 | }; |
180 | 180 | } |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | */ |
249 | 249 | function all(callable ...$functions) : \Closure |
250 | 250 | { |
251 | - return function (...$args) use ($functions) { |
|
251 | + return function(...$args) use ($functions) { |
|
252 | 252 | foreach ($functions as $function) { |
253 | 253 | if (!$function(...$args)) { |
254 | 254 | return false; |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | */ |
278 | 278 | function any(callable ...$functions) : \Closure |
279 | 279 | { |
280 | - return function (...$args) use ($functions) { |
|
280 | + return function(...$args) use ($functions) { |
|
281 | 281 | foreach ($functions as $function) { |
282 | 282 | if ($function(...$args)) { |
283 | 283 | return true; |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | function not($predicate) : \Closure |
323 | 323 | { |
324 | 324 | $predicate = predicate($predicate); |
325 | - return function (...$arguments) use ($predicate) { |
|
325 | + return function(...$arguments) use ($predicate) { |
|
326 | 326 | return !$predicate(...$arguments); |
327 | 327 | }; |
328 | 328 | } |
@@ -350,13 +350,13 @@ discard block |
||
350 | 350 | */ |
351 | 351 | function argument(int $offset, callable $predicate, $length = true) : \Closure |
352 | 352 | { |
353 | - if($length === true) { |
|
353 | + if ($length === true) { |
|
354 | 354 | $length = 1; |
355 | - } elseif($length === false) { |
|
355 | + } elseif ($length === false) { |
|
356 | 356 | $length = null; |
357 | 357 | } |
358 | 358 | |
359 | - return function (...$arguments) use ($predicate, $offset, $length) { |
|
359 | + return function(...$arguments) use ($predicate, $offset, $length) { |
|
360 | 360 | return $predicate(...array_slice($arguments, $offset, $length, false)); |
361 | 361 | }; |
362 | 362 | } |
@@ -379,9 +379,9 @@ discard block |
||
379 | 379 | */ |
380 | 380 | function consecutive(callable ...$predicates) |
381 | 381 | { |
382 | - return function (...$arguments) use ($predicates) { |
|
382 | + return function(...$arguments) use ($predicates) { |
|
383 | 383 | foreach ($arguments as $index => $value) { |
384 | - if(!$predicates[$index]($value)) { |
|
384 | + if (!$predicates[$index]($value)) { |
|
385 | 385 | return false; |
386 | 386 | } |
387 | 387 | } |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | function property($name, $value) { |
394 | 394 | $predicate = $value instanceof \Closure ? $value : \Kadet\Xmpp\Utils\filter\equals($value); |
395 | 395 | |
396 | - return function ($element) use ($name, $predicate) { |
|
396 | + return function($element) use ($name, $predicate) { |
|
397 | 397 | return $predicate($element->$name); |
398 | 398 | }; |
399 | 399 | } |
@@ -26,9 +26,9 @@ discard block |
||
26 | 26 | function typeof($value) : string |
27 | 27 | { |
28 | 28 | if (is_object($value)) { |
29 | - return "object of type ".get_class($value); |
|
29 | + return "object of type " . get_class($value); |
|
30 | 30 | } elseif (is_resource($value)) { |
31 | - return get_resource_type($value).' resource'; |
|
31 | + return get_resource_type($value) . ' resource'; |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | return gettype($value); |
@@ -36,10 +36,10 @@ discard block |
||
36 | 36 | |
37 | 37 | function partial(callable $callable, $argument, int $position = 0) : callable |
38 | 38 | { |
39 | - return function (...$arguments) use ($callable, $argument, $position) { |
|
39 | + return function(...$arguments) use ($callable, $argument, $position) { |
|
40 | 40 | $arguments = array_merge( |
41 | 41 | array_slice($arguments, 0, $position), |
42 | - [ $argument ], |
|
42 | + [$argument], |
|
43 | 43 | array_slice($arguments, $position) |
44 | 44 | ); |
45 | 45 | |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | |
50 | 50 | function dump($value) |
51 | 51 | { |
52 | - echo Dumper::get()->dump($value).PHP_EOL.PHP_EOL; |
|
52 | + echo Dumper::get()->dump($value) . PHP_EOL . PHP_EOL; |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | function dd($value) |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | |
61 | 61 | function format($string, array $arguments = []) |
62 | 62 | { |
63 | - return str_replace(array_map(function ($e) { return "{{$e}}"; }, array_keys($arguments)), $arguments, $string); |
|
63 | + return str_replace(array_map(function($e) { return "{{$e}}"; }, array_keys($arguments)), $arguments, $string); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | function rearrange(array $array, array $keys) : array |
@@ -75,9 +75,9 @@ discard block |
||
75 | 75 | function copy(array $array) |
76 | 76 | { |
77 | 77 | return array_map(function($element) { |
78 | - if(is_array($element)) { |
|
78 | + if (is_array($element)) { |
|
79 | 79 | return copy($element); |
80 | - } elseif(is_object($element)) { |
|
80 | + } elseif (is_object($element)) { |
|
81 | 81 | return clone $element; |
82 | 82 | } |
83 | 83 |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | |
48 | 48 | public function setClient(XmppClient $client) |
49 | 49 | { |
50 | - if($this->_client !== null) { |
|
50 | + if ($this->_client !== null) { |
|
51 | 51 | throw new BadMethodCallException("You cannot change rosters XmppClient instance."); |
52 | 52 | } |
53 | 53 | |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | private function handleSet(Iq\Query\Roster $query) |
73 | 73 | { |
74 | 74 | foreach ($query->items as $item) { |
75 | - if($item->subscription == 'remove') { |
|
75 | + if ($item->subscription == 'remove') { |
|
76 | 76 | $this->removeItem($item->jid); |
77 | 77 | } else { |
78 | 78 | $this->setItem($item); |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | |
170 | 170 | $iq = new Iq('remove', ['query' => new Iq\Query\Roster()]); |
171 | 171 | /** @var Iq\Query\Roster\Item $item */ |
172 | - foreach($remove as $item) { |
|
172 | + foreach ($remove as $item) { |
|
173 | 173 | $iq->query->append(new Iq\Query\Roster\Item($item->jid, ['subscription' => 'remove'])); |
174 | 174 | } |
175 | 175 | |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | public function update(Iq\Query\Roster\Item $item) |
187 | 187 | { |
188 | 188 | $iq = new Iq('set', ['query' => new Iq\Query\Roster([ |
189 | - 'items' => [ $item ] |
|
189 | + 'items' => [$item] |
|
190 | 190 | ])]); |
191 | 191 | |
192 | 192 | return $this->_client->send($iq); |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | |
275 | 275 | private function setItem(Iq\Query\Roster\Item $item) |
276 | 276 | { |
277 | - $this->emit('item', [ $item ]); |
|
277 | + $this->emit('item', [$item]); |
|
278 | 278 | $this->_items[(string)$item->jid] = $item; |
279 | 279 | } |
280 | 280 | |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | return; |
288 | 288 | } |
289 | 289 | |
290 | - $this->emit('remove', [ $this->_items[(string)$jid] ]); |
|
290 | + $this->emit('remove', [$this->_items[(string)$jid]]); |
|
291 | 291 | unset($this->_items[(string)$jid]); |
292 | 292 | } |
293 | 293 | } |
@@ -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 |