Completed
Push — master ( 641e7a...5eff09 )
by Kacper
02:52
created
Utils/BetterEmitter.php 2 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -32,6 +32,10 @@
 block discarded – undo
32 32
         return $this->addListener($event, $this->getConditionalCallable($listener, $condition), $priority);
33 33
     }
34 34
 
35
+    /**
36
+     * @param string $event
37
+     * @param \Closure $condition
38
+     */
35 39
     public function once($event, callable $listener, $condition = null, int $priority = 0)
36 40
     {
37 41
         return $this->on($event, $this->getOnceCallable($this->getConditionalCallable($listener, $condition), $event), null, $priority);
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
             }
Please login to merge, or discard this patch.
Module/Binding.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -30,18 +30,18 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
     }
Please login to merge, or discard this patch.
Utils/Filter.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -25,8 +25,8 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Xml/XmlStream.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -76,32 +76,32 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Stanza/Stanza.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
XmppClient.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -109,11 +109,11 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
     }
Please login to merge, or discard this patch.
Module/SaslAuthenticator.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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]);
Please login to merge, or discard this patch.
Xml/XmlElement.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.