Completed
Push — master ( 528f7d...f4b721 )
by Kacper
04:19
created
Xml/XmlElement.php 2 patches
Doc Comments   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
      * Retrieves array of matching elements
221 221
      *
222 222
      * @param string $name  Requested element tag name
223
-     * @param null   $uri   Requested element namespace
223
+     * @param null|string   $uri   Requested element namespace
224 224
      *
225 225
      * @return XmlElement[] Found Elements
226 226
      */
@@ -248,6 +248,9 @@  discard block
 block discarded – undo
248 248
         return $this->elements($name, $uri)[$index] ?? false;
249 249
     }
250 250
 
251
+    /**
252
+     * @param \Closure $predicate
253
+     */
251 254
     public function all($predicate) {
252 255
         $predicate = filter\predicate($predicate);
253 256
         return array_filter($this->_children, $predicate);
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -68,27 +68,27 @@  discard block
 block discarded – undo
68 68
 
69 69
     public function xml($clean = true): string
70 70
     {
71
-        if($this->namespace && $this->_prefix === null) {
71
+        if ($this->namespace && $this->_prefix === null) {
72 72
             $this->_prefix = $this->lookupPrefix($this->namespace);
73 73
         }
74 74
 
75 75
         $attributes = $this->attributes();
76 76
 
77 77
         $result = "<{$this->name}";
78
-        $result .= ' '.implode(' ', array_map(function($key, $value) {
79
-            return $key.'="'.htmlspecialchars($value, ENT_QUOTES).'"';
78
+        $result .= ' ' . implode(' ', array_map(function($key, $value) {
79
+            return $key . '="' . htmlspecialchars($value, ENT_QUOTES) . '"';
80 80
         }, array_keys($attributes), array_values($attributes)));
81 81
 
82
-        if(!empty($this->_children)) {
83
-            $result .= ">".implode('', array_map(function($element) {
84
-                if(is_string($element)) {
82
+        if (!empty($this->_children)) {
83
+            $result .= ">" . implode('', array_map(function($element) {
84
+                if (is_string($element)) {
85 85
                     return htmlspecialchars($element);
86 86
                 } elseif ($element instanceof XmlElement) {
87 87
                     return $element->xml(false);
88 88
                 }
89 89
 
90 90
                 return (string)$element;
91
-            }, $this->_children))."</{$this->name}>";
91
+            }, $this->_children)) . "</{$this->name}>";
92 92
         } else {
93 93
             $result .= "/>";
94 94
         }
@@ -98,12 +98,12 @@  discard block
 block discarded – undo
98 98
 
99 99
     public function setAttribute(string $attribute, $value, string $uri = null)
100 100
     {
101
-        if($uri === 'http://www.w3.org/2000/xmlns/') {
101
+        if ($uri === 'http://www.w3.org/2000/xmlns/') {
102 102
             $this->_namespaces[(string)$value] = $attribute;
103 103
             return;
104 104
         }
105 105
 
106
-        if($uri !== null) {
106
+        if ($uri !== null) {
107 107
             $attribute = $this->_prefix($attribute, $uri);
108 108
         }
109 109
 
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 
113 113
     public function getAttribute(string $attribute, string $uri = null)
114 114
     {
115
-        if($uri !== null) {
115
+        if ($uri !== null) {
116 116
             $attribute = $this->_prefix($attribute, $uri);
117 117
         }
118 118
 
@@ -124,11 +124,11 @@  discard block
 block discarded – undo
124 124
      */
125 125
     public function getNamespaces($parent = true): array
126 126
     {
127
-        if(!$this->_parent) {
127
+        if (!$this->_parent) {
128 128
             return $this->_namespaces;
129 129
         }
130 130
 
131
-        if($parent) {
131
+        if ($parent) {
132 132
             return array_merge($this->_namespaces, $this->_parent->getNamespaces());
133 133
         } else {
134 134
             return array_diff_assoc($this->_namespaces, $this->_parent->getNamespaces());
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
     {
140 140
         $namespaces = $this->getNamespaces(false);
141 141
         $namespaces = array_map(function($prefix, $uri) {
142
-            return [ $prefix ? "xmlns:{$prefix}" : 'xmlns', $uri ];
142
+            return [$prefix ? "xmlns:{$prefix}" : 'xmlns', $uri];
143 143
         }, array_values($namespaces), array_keys($namespaces));
144 144
 
145 145
         return array_merge(
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 
161 161
     public function setNamespace(string $uri, $prefix = false)
162 162
     {
163
-        if($prefix === false) {
163
+        if ($prefix === false) {
164 164
             $prefix = $this->_prefix;
165 165
         }
166 166
 
@@ -179,15 +179,15 @@  discard block
 block discarded – undo
179 179
 
180 180
     public function append($element)
181 181
     {
182
-        if(!is_string($element) && !$element instanceof XmlElement) {
182
+        if (!is_string($element) && !$element instanceof XmlElement) {
183 183
             throw new InvalidArgumentException(helper\format('$element should be either string or object of {class} class, {type} given', [
184 184
                 'class' => XmlElement::class,
185 185
                 'type'  => helper\typeof($element)
186 186
             ]));
187 187
         }
188 188
 
189
-        if($element instanceof XmlElement) {
190
-            $element->parent  = $this;
189
+        if ($element instanceof XmlElement) {
190
+            $element->parent = $this;
191 191
         }
192 192
 
193 193
         $this->_children[] = $element;
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 
196 196
     public function getName()
197 197
     {
198
-        return ($this->_prefix ? $this->prefix.':' : null).$this->localName;
198
+        return ($this->_prefix ? $this->prefix . ':' : null) . $this->localName;
199 199
     }
200 200
 
201 201
     public function getPrefix()
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
     protected function setParent(XmlElement $parent)
212 212
     {
213 213
         $this->_parent = $parent;
214
-        if($this->namespace === false) {
214
+        if ($this->namespace === false) {
215 215
             $this->namespace = $parent->namespace;
216 216
         }
217 217
     }
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
     public function elements($name, $uri = null) : array
228 228
     {
229 229
         $predicate = filter\tag($name);
230
-        if($uri !== null) {
230
+        if ($uri !== null) {
231 231
             $predicate = filter\all($predicate, filter\xmlns($uri));
232 232
         }
233 233
 
Please login to merge, or discard this patch.
Xml/XPathQuery.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
     public function query(string $query = null)
34 34
     {
35 35
         /** @var \DOMNode $element */
36
-        foreach($this->_xpath->query($query ?: $this->_query) as $element) {
36
+        foreach ($this->_xpath->query($query ?: $this->_query) as $element) {
37 37
             yield $this->getElementFromPath($element->getNodePath());
38 38
         }
39 39
     }
@@ -70,14 +70,14 @@  discard block
 block discarded – undo
70 70
         array_shift($path);
71 71
 
72 72
         $current = $this->_context;
73
-        foreach($path as $chunk) {
73
+        foreach ($path as $chunk) {
74 74
             // Chunk is in format node-name[index], parse it with regex
75 75
             preg_match('/([\w\*]+)(?:\[([0-9]+)\])?/', $chunk, $matches);
76 76
 
77 77
             $name  = $matches[1];
78 78
             $index = isset($matches[2]) ? $matches[2] - 1 : 0;
79 79
 
80
-            if($name == '*') {
80
+            if ($name == '*') {
81 81
                 // Path returns * if namespace occurs so we need to obtain index-th child
82 82
                 $current = $current->children[$index];
83 83
             } else {
Please login to merge, or discard this patch.
Xml/XmlStream.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -76,25 +76,25 @@  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
             $this->emit('element', $arguments);
96 96
         });
97
-        $this->on('close', function () { $this->_isOpened = false; });
97
+        $this->on('close', function() { $this->_isOpened = false; });
98 98
     }
99 99
 
100 100
     /**
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
      */
107 107
     public function write($data)
108 108
     {
109
-        $this->emit('send.'.($data instanceof XmlElement ? 'element' : 'text'), [ $data ]);
109
+        $this->emit('send.' . ($data instanceof XmlElement ? 'element' : 'text'), [$data]);
110 110
 
111 111
         return parent::write($data);
112 112
     }
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
      */
137 137
     public function close()
138 138
     {
139
-        if($this->isOpened()) {
139
+        if ($this->isOpened()) {
140 140
             $this->write('</stream:stream>');
141 141
             $this->_isOpened = false;
142 142
         }
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 
172 172
     private function handleError(Error $element)
173 173
     {
174
-        if($this->emit('stream.error', [ $element ])) {
174
+        if ($this->emit('stream.error', [$element])) {
175 175
             throw new StreamErrorException($element);
176 176
         }
177 177
 
Please login to merge, or discard this patch.
Xml/XmlParser.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -71,13 +71,13 @@  discard block
 block discarded – undo
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 ($parser, $name) {
76
+        }, function($parser, $name) {
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
 
@@ -119,10 +119,10 @@  discard block
 block discarded – undo
119 119
         list($attributes, $namespaces) = $this->_attributes($attrs);
120 120
         list($tag, $prefix)            = XmlElement::resolve($name);
121 121
 
122
-        $uri   = $this->_lookup($prefix, $namespaces);
122
+        $uri = $this->_lookup($prefix, $namespaces);
123 123
 
124 124
         /** @var XmlElement $element */
125
-        $element = $this->factory->create($uri, $tag, [ $name, $uri ]);
125
+        $element = $this->factory->create($uri, $tag, [$name, $uri]);
126 126
         foreach ($attributes as $name => $value) {
127 127
             $element->setAttribute($name, $value);
128 128
         }
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
         if (count($this->_stack) > 1) {
138 138
             end($this->_stack)->append($element);
139 139
         }
140
-        $this->emit('parse.begin', [ $element ]);
140
+        $this->emit('parse.begin', [$element]);
141 141
 
142 142
         $this->_stack[] = $element;
143 143
     }
@@ -150,10 +150,10 @@  discard block
 block discarded – undo
150 150
 
151 151
         $element = array_pop($this->_stack);
152 152
         if (count($this->_stack) == 1) {
153
-            $this->emit('element', [ $element ]);
153
+            $this->emit('element', [$element]);
154 154
         }
155 155
 
156
-        $this->emit('parse.end', [ $element ]);
156
+        $this->emit('parse.end', [$element]);
157 157
     }
158 158
 
159 159
     private function handleTextData($data)
Please login to merge, or discard this patch.
Network/Connector/TcpXmppConnector.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -41,14 +41,14 @@
 block discarded – undo
41 41
                 'port' => $port
42 42
             ]);
43 43
 
44
-            if($stream = @stream_socket_client("tcp://$ip:$port")) {
44
+            if ($stream = @stream_socket_client("tcp://$ip:$port")) {
45 45
                 $stream = new TcpStream($stream, $this->_loop);
46
-                $this->emit('connect', [ $stream ]);
46
+                $this->emit('connect', [$stream]);
47 47
                 return $stream;
48 48
             }
49 49
         }
50 50
 
51
-        throw new \RuntimeException('Cannot connect to '.$this->_host);
51
+        throw new \RuntimeException('Cannot connect to ' . $this->_host);
52 52
     }
53 53
 
54 54
     public function __construct(string $host, LoopInterface $loop)
Please login to merge, or discard this patch.
XmppStream.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -37,15 +37,15 @@
 block discarded – undo
37 37
         parent::__construct($parser, $transport);
38 38
 
39 39
         $this->_parser->factory->register(Features::class, self::NAMESPACE_URI, 'features');
40
-        $this->_parser->factory->register(Error::class,    self::NAMESPACE_URI, 'error');
40
+        $this->_parser->factory->register(Error::class, self::NAMESPACE_URI, 'error');
41 41
 
42 42
         $this->_lang = $lang;
43 43
 
44
-        $this->on('element', function (Features $element) {
44
+        $this->on('element', function(Features $element) {
45 45
             $this->handleFeatures($element);
46 46
         }, Features::class);
47 47
 
48
-        $this->on('element', function (XmlElement $element) {
48
+        $this->on('element', function(XmlElement $element) {
49 49
             $this->handleTls($element);
50 50
         }, with\xmlns(self::TLS_NAMESPACE));
51 51
     }
Please login to merge, or discard this patch.
Utils/StreamDecorator.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php declare(strict_types=1);
1
+<?php declare(strict_types = 1);
2 2
 /**
3 3
  * XMPP Library
4 4
  *
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
      */
37 37
     public function __construct(DuplexStreamInterface $decorated = null)
38 38
     {
39
-        if($decorated !== null) {
39
+        if ($decorated !== null) {
40 40
             $this->exchangeStream($decorated);
41 41
         }
42 42
     }
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
     {
86 86
         static $events = ['data', 'end', 'drain', 'error', 'close', 'pipe'];
87 87
 
88
-        if($this->_decorated !== null) {
88
+        if ($this->_decorated !== null) {
89 89
             $this->unsubscribe($this->_decorated, $events);
90 90
         }
91 91
 
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
     private function unsubscribe(DuplexStreamInterface $stream, array $events)
97 97
     {
98 98
         foreach ($events as $event) {
99
-            if(!isset($this->_redirectors[$event])) {
99
+            if (!isset($this->_redirectors[$event])) {
100 100
                 continue;
101 101
             }
102 102
 
@@ -107,8 +107,8 @@  discard block
 block discarded – undo
107 107
     private function subscribe(DuplexStreamInterface $stream, array $events)
108 108
     {
109 109
         foreach ($events as $event) {
110
-            if(!isset($this->_redirectors[$event])) {
111
-                $this->_redirectors[$event] = function (...$arguments) use ($event) {
110
+            if (!isset($this->_redirectors[$event])) {
111
+                $this->_redirectors[$event] = function(...$arguments) use ($event) {
112 112
                     $this->emit($event, $arguments);
113 113
                 };
114 114
             }
Please login to merge, or discard this patch.
Utils/Dumper.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -37,16 +37,16 @@  discard block
 block discarded – undo
37 37
 
38 38
     private function getDumper($value)
39 39
     {
40
-        if(is_object($value)) {
40
+        if (is_object($value)) {
41 41
             $class = get_class($value);
42 42
             foreach (array_merge([$class], class_parents($class), class_implements($class)) as $class) {
43
-                if(isset($this->_dumpers[$class])) {
43
+                if (isset($this->_dumpers[$class])) {
44 44
                     return $this->_dumpers[$class];
45 45
                 }
46 46
             }
47 47
         }
48 48
 
49
-        if(isset($this->_dumpers[gettype($value)])) {
49
+        if (isset($this->_dumpers[gettype($value)])) {
50 50
             return $this->_dumpers[gettype($value)];
51 51
         }
52 52
 
@@ -72,9 +72,9 @@  discard block
 block discarded – undo
72 72
     {
73 73
         $console = Console::get();
74 74
 
75
-        $result = $console->styled(['color' => 'yellow'], 'array').' with '.$console->styled(['color' => 'magenta'], count($array)).' elements:'.PHP_EOL;
76
-        foreach($array as $key => $value) {
77
-            $result .= "\t".str_replace("\n", "\n\t", '['.$this->dump($key).']: '.$this->dump($value)).PHP_EOL;
75
+        $result = $console->styled(['color' => 'yellow'], 'array') . ' with ' . $console->styled(['color' => 'magenta'], count($array)) . ' elements:' . PHP_EOL;
76
+        foreach ($array as $key => $value) {
77
+            $result .= "\t" . str_replace("\n", "\n\t", '[' . $this->dump($key) . ']: ' . $this->dump($value)) . PHP_EOL;
78 78
         }
79 79
 
80 80
         return $result;
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 
83 83
     public function init()
84 84
     {
85
-        $this->register('array',  [$this, '_dumpArray']);
85
+        $this->register('array', [$this, '_dumpArray']);
86 86
         $this->register('object', [$this, '_dumpObject']);
87 87
     }
88 88
 }
Please login to merge, or discard this patch.
Utils/DnsResolver.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@
 block discarded – undo
54 54
                 continue;
55 55
             }
56 56
 
57
-            $this->_results = array_merge($this->_results, array_map(function ($record) {
57
+            $this->_results = array_merge($this->_results, array_map(function($record) {
58 58
                 return [$record['target'], $record['port']];
59 59
             }, $result));
60 60
         }
Please login to merge, or discard this patch.