Passed
Push — master ( 970a98...e723e3 )
by y
03:01 queued 01:01
created
src/DatagramClient.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@
 block discarded – undo
10 10
     /**
11 11
      * @return int `SOCK_DGRAM`
12 12
      */
13
-    final public static function getType () {
13
+    final public static function getType() {
14 14
         return SOCK_DGRAM;
15 15
     }
16 16
 
Please login to merge, or discard this patch.
src/AbstractServer.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
      *
15 15
      * @return string
16 16
      */
17
-    public function __toString () {
17
+    public function __toString() {
18 18
         try {
19 19
             return implode(':', $this->getSockName());
20 20
         }
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
      * @throws Error
37 37
      * @return $this
38 38
      */
39
-    public function bind ($address, $port = 0) {
39
+    public function bind($address, $port = 0) {
40 40
         if (!@socket_bind($this->resource, $address, $port)) {
41 41
             throw new Error($this->resource, SOCKET_EOPNOTSUPP);
42 42
         }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -17,8 +17,7 @@
 block discarded – undo
17 17
     public function __toString () {
18 18
         try {
19 19
             return implode(':', $this->getSockName());
20
-        }
21
-        catch (\Exception $e) {
20
+        } catch (\Exception $e) {
22 21
             return ':';
23 22
         }
24 23
     }
Please login to merge, or discard this patch.
src/Reactor.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
      * @param ReactiveInterface $socket
23 23
      * @return $this
24 24
      */
25
-    public function add (ReactiveInterface $socket) {
25
+    public function add(ReactiveInterface $socket) {
26 26
         $this->sockets[$socket->getId()] = $socket;
27 27
         return $this;
28 28
     }
@@ -32,14 +32,14 @@  discard block
 block discarded – undo
32 32
      *
33 33
      * @return int
34 34
      */
35
-    public function count () {
35
+    public function count() {
36 36
         return count($this->sockets);
37 37
     }
38 38
 
39 39
     /**
40 40
      * @return SocketInterface[]
41 41
      */
42
-    public function getSockets () {
42
+    public function getSockets() {
43 43
         return $this->sockets;
44 44
     }
45 45
 
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
      * @throws Error
51 51
      * @return int Number of sockets that reacted.
52 52
      */
53
-    public function react ($timeout = null) {
53
+    public function react($timeout = null) {
54 54
         /** @var ReactiveInterface[][] $rwe */
55 55
         $rwe = [$this->sockets, [], $this->sockets];
56 56
         $count = AbstractSocket::select($rwe[0], $rwe[1], $rwe[2], $timeout);
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
      * @param int $id
70 70
      * @return $this
71 71
      */
72
-    public function remove ($id) {
72
+    public function remove($id) {
73 73
         unset($this->sockets[$id]);
74 74
         return $this;
75 75
     }
Please login to merge, or discard this patch.
src/StreamClient.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
      * @return static[] Two instances at indices `0` and `1`.
17 17
      * @throws Error
18 18
      */
19
-    public static function createUnixPair (...$extra) {
19
+    public static function createUnixPair(...$extra) {
20 20
         if (!@socket_create_pair(AF_UNIX, SOCK_STREAM, 0, $fd)) {
21 21
             throw new Error; // reliable errno
22 22
         }
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
     /**
30 30
      * @return int `SOCK_STREAM`
31 31
      */
32
-    final public static function getType () {
32
+    final public static function getType() {
33 33
         return SOCK_STREAM;
34 34
     }
35 35
 
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
      * @return string
44 44
      * @throws Error With extra data set to the partially received data.
45 45
      */
46
-    public function read ($length) {
46
+    public function read($length) {
47 47
         $data = '';
48 48
         while ($length > 0) {
49 49
             try {
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
      * @throws Error
74 74
      * @return string
75 75
      */
76
-    public function recv ($length, $flags = 0) {
76
+    public function recv($length, $flags = 0) {
77 77
         $count = @socket_recv($this->resource, $data, $length, $flags);
78 78
         if ($count === false) {
79 79
             $error = new Error($this->resource, SOCKET_EINVAL);
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -52,8 +52,7 @@
 block discarded – undo
52 52
                 if ($chunk === '') {
53 53
                     return $data;
54 54
                 }
55
-            }
56
-            catch (Error $error) {
55
+            } catch (Error $error) {
57 56
                 $error->setExtra($data);
58 57
                 throw $error;
59 58
             }
Please login to merge, or discard this patch.
src/AbstractClient.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
      *
15 15
      * @return string
16 16
      */
17
-    public function __toString () {
17
+    public function __toString() {
18 18
         try {
19 19
             return implode(':', $this->getPeerName());
20 20
         }
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
      * @throws Error
39 39
      * @return $this
40 40
      */
41
-    public function connect ($address, $port = 0) {
41
+    public function connect($address, $port = 0) {
42 42
         if (!@socket_connect($this->resource, $address, $port)) {
43 43
             // ignore expected errors for non-blocking connections
44 44
             $errno = Error::getLast($this->resource);
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
      * @throws Error
59 59
      * @return array Name and port at indices `0` and `1`.
60 60
      */
61
-    public function getPeerName () {
61
+    public function getPeerName() {
62 62
         if ($this->domain === AF_UNIX) {
63 63
             return [$this->getOption(self::SO_PEERCRED), 0];
64 64
         }
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
      * @throws Error
81 81
      * @return int Total bytes sent.
82 82
      */
83
-    public function send ($data, $flags = 0) {
83
+    public function send($data, $flags = 0) {
84 84
         $count = @socket_send($this->resource, $data, PHP_INT_MAX, $flags);
85 85
         if ($count === false) {
86 86
             $error = new Error($this->resource); // reliable errno
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
      * @throws Error Total bytes sent is set in the extra data.
100 100
      * @return $this
101 101
      */
102
-    public function write ($data) {
102
+    public function write($data) {
103 103
         $data = (string)$data;
104 104
         $length = strlen($data);
105 105
         $total = 0;
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -17,8 +17,7 @@  discard block
 block discarded – undo
17 17
     public function __toString () {
18 18
         try {
19 19
             return implode(':', $this->getPeerName());
20
-        }
21
-        catch (\Exception $exception) {
20
+        } catch (\Exception $exception) {
22 21
             return ':';
23 22
         }
24 23
     }
@@ -107,8 +106,7 @@  discard block
 block discarded – undo
107 106
             try {
108 107
                 $total += $count = $this->await(self::CH_WRITE)->send($data);
109 108
                 $data = substr($data, $count); // 0 bytes sent = unaltered buffer
110
-            }
111
-            catch (Error $error) {
109
+            } catch (Error $error) {
112 110
                 $error->setExtra($total);
113 111
                 throw $error;
114 112
             }
Please login to merge, or discard this patch.
src/DatagramServer.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
     /**
11 11
      * @return int `SOCK_DGRAM`
12 12
      */
13
-    final public static function getType () {
13
+    final public static function getType() {
14 14
         return SOCK_DGRAM;
15 15
     }
16 16
 
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
      * @throws Error
29 29
      * @return string
30 30
      */
31
-    public function recv ($length, $flags = 0, &$name = null, &$port = 0) {
31
+    public function recv($length, $flags = 0, &$name = null, &$port = 0) {
32 32
         $count = @socket_recvfrom($this->resource, $data, $length, $flags, $name, $port);
33 33
         if ($count === false) {
34 34
             $error = new Error($this->resource, SOCKET_EOPNOTSUPP);
Please login to merge, or discard this patch.
src/StreamServer.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
     /**
11 11
      * @return int `SOCK_STREAM`
12 12
      */
13
-    final public static function getType () {
13
+    final public static function getType() {
14 14
         return SOCK_STREAM;
15 15
     }
16 16
 
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
      * @throws Error
26 26
      * @return StreamClient The accepted connection, as a client instance.
27 27
      */
28
-    public function accept () {
28
+    public function accept() {
29 29
         if (!$resource = @socket_accept($this->resource)) {
30 30
             throw new Error($this->resource); // reliable errno
31 31
         }
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
      * @return StreamClient
42 42
      * @throws Error
43 43
      */
44
-    protected function createClient ($resource) {
44
+    protected function createClient($resource) {
45 45
         return new StreamClient($resource);
46 46
     }
47 47
 
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
      * @throws Error
56 56
      * @return $this
57 57
      */
58
-    public function listen ($backlog = 0) {
58
+    public function listen($backlog = 0) {
59 59
         if (!@socket_listen($this->resource, $backlog)) {
60 60
             throw new Error($this->resource); // reliable errno
61 61
         }
@@ -68,6 +68,6 @@  discard block
 block discarded – undo
68 68
      * @param StreamClient $client
69 69
      * @return void
70 70
      */
71
-    protected function onAccept (StreamClient $client) { }
71
+    protected function onAccept(StreamClient $client) { }
72 72
 
73 73
 }
Please login to merge, or discard this patch.
src/AbstractSocket.php 2 patches
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
      * @return static
41 41
      * @throws Error
42 42
      */
43
-    public static function create ($domain = AF_INET, ...$extra) {
43
+    public static function create($domain = AF_INET, ...$extra) {
44 44
         if (!$resource = @socket_create($domain, static::getType(), 0)) { // auto-protocol
45 45
             throw new Error; // reliable errno
46 46
         }
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
     /**
51 51
      * @return int
52 52
      */
53
-    public static function getType () {
53
+    public static function getType() {
54 54
         return 0;
55 55
     }
56 56
 
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
      * @return int
67 67
      * @throws Error
68 68
      */
69
-    public static function select (array &$read, array &$write, array &$except, $timeout = null) {
69
+    public static function select(array &$read, array &$write, array &$except, $timeout = null) {
70 70
         $rwe = [$read, $write, $except];
71 71
         array_walk_recursive($rwe, function(SocketInterface &$socket) {
72 72
             $socket = $socket->getResource();
@@ -93,12 +93,12 @@  discard block
 block discarded – undo
93 93
      * @throws Error (`SOCKET_EBADFD`) There was a pending error on the socket, including `SO_ERROR`.
94 94
      * The existing error code is set in the extra data.
95 95
      */
96
-    public function __construct ($resource) {
96
+    public function __construct($resource) {
97 97
         if (!is_resource($resource) or get_resource_type($resource) !== 'Socket') {
98 98
             throw new InvalidArgumentException('Expected an open socket resource.', SOCKET_EBADF);
99 99
         }
100 100
         elseif (socket_get_option($resource, SOL_SOCKET, SO_TYPE) !== static::getType()) {
101
-            throw new InvalidArgumentException('The given socket resource is of the wrong type for ' . get_class(), SOCKET_ESOCKTNOSUPPORT);
101
+            throw new InvalidArgumentException('The given socket resource is of the wrong type for '.get_class(), SOCKET_ESOCKTNOSUPPORT);
102 102
         }
103 103
         elseif ($errno = Error::getLast($resource)) {
104 104
             $error = new Error(SOCKET_EBADFD);
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
     /**
114 114
      * Closes the socket if it's open.
115 115
      */
116
-    public function __destruct () {
116
+    public function __destruct() {
117 117
         $this->close();
118 118
     }
119 119
 
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
      * @return $this
129 129
      * @throws Error
130 130
      */
131
-    public function await ($channel) {
131
+    public function await($channel) {
132 132
         $select = [$channel => [$this->resource]];
133 133
         $count = @socket_select($select[self::CH_READ], $select[self::CH_WRITE], $select[self::CH_EXCEPT], null);
134 134
         if (!$count) {
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
      *
149 149
      * @return $this
150 150
      */
151
-    public function close () {
151
+    public function close() {
152 152
         // socket_close() never errors, but we guard anyway to prevent
153 153
         // a redundant call to onClose(), and an incorrect call to it if
154 154
         // the constructor failed and the destructor is calling this.
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
     /**
163 163
      * @return int
164 164
      */
165
-    final public function getDomain () {
165
+    final public function getDomain() {
166 166
         return $this->domain;
167 167
     }
168 168
 
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
      *
174 174
      * @return int
175 175
      */
176
-    final public function getId () {
176
+    final public function getId() {
177 177
         return (int)$this->resource;
178 178
     }
179 179
 
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
      * @throws Error The socket has no such option or is closed.
187 187
      * @return mixed The option's value. This is never `false`.
188 188
      */
189
-    public function getOption ($option) {
189
+    public function getOption($option) {
190 190
         $value = @socket_get_option($this->resource, SOL_SOCKET, $option);
191 191
         if ($value === false) {
192 192
             throw new Error($this->resource, SOCKET_EINVAL);
@@ -197,14 +197,14 @@  discard block
 block discarded – undo
197 197
     /**
198 198
      * @return int
199 199
      */
200
-    final public function getProtocol () {
200
+    final public function getProtocol() {
201 201
         return $this->protocol;
202 202
     }
203 203
 
204 204
     /**
205 205
      * @return resource
206 206
      */
207
-    final public function getResource () {
207
+    final public function getResource() {
208 208
         return $this->resource;
209 209
     }
210 210
 
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
      * @throws Error
217 217
      * @return array String address and integer port at indices `0` and `1`.
218 218
      */
219
-    public function getSockName () {
219
+    public function getSockName() {
220 220
         if (!@socket_getsockname($this->resource, $addr, $port)) {
221 221
             throw new Error($this->resource, SOCKET_EOPNOTSUPP);
222 222
         }
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
      * @return bool
232 232
      * @throws Error
233 233
      */
234
-    public function isExceptional () {
234
+    public function isExceptional() {
235 235
         return $this->isReady(self::CH_EXCEPT);
236 236
     }
237 237
 
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
      *
241 241
      * @return bool
242 242
      */
243
-    public function isOpen () {
243
+    public function isOpen() {
244 244
         return is_resource($this->resource);
245 245
     }
246 246
 
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
      * @return bool
253 253
      * @throws Error
254 254
      */
255
-    public function isReadable () {
255
+    public function isReadable() {
256 256
         return $this->isReady(self::CH_READ);
257 257
     }
258 258
 
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
      * @throws Error
267 267
      * @return bool
268 268
      */
269
-    public function isReady ($channel, $timeout = 0.0) {
269
+    public function isReady($channel, $timeout = 0.0) {
270 270
         $usec = (int)(fmod($timeout, 1) * 1000000); // ignored if timeout is null
271 271
         $select = [$channel => [$this->resource]];
272 272
         $count = $count = @socket_select($select[self::CH_READ], $select[self::CH_WRITE], $select[self::CH_EXCEPT], $timeout, $usec);
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
      * @return bool
285 285
      * @throws Error
286 286
      */
287
-    public function isWritable () {
287
+    public function isWritable() {
288 288
         return $this->isReady(self::CH_WRITE, 0);
289 289
     }
290 290
 
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
      *
294 294
      * @return void
295 295
      */
296
-    protected function onClose () { }
296
+    protected function onClose() { }
297 297
 
298 298
     /**
299 299
      * Stub. Called before an I/O channel is shut down.
@@ -301,14 +301,14 @@  discard block
 block discarded – undo
301 301
      * @param int $channel
302 302
      * @return void
303 303
      */
304
-    protected function onShutdown ($channel) { }
304
+    protected function onShutdown($channel) { }
305 305
 
306 306
     /**
307 307
      * Stub. Called when an I/O timeout has occurred, before it is thrown.
308 308
      *
309 309
      * @return void
310 310
      */
311
-    protected function onTimeout () { }
311
+    protected function onTimeout() { }
312 312
 
313 313
     /**
314 314
      * Enables or disables blocking.
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
      * @throws Error
329 329
      * @return $this
330 330
      */
331
-    public function setBlocking ($blocking) {
331
+    public function setBlocking($blocking) {
332 332
         if ($blocking) {
333 333
             $success = @socket_set_block($this->resource);
334 334
         }
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
      * @throws Error
352 352
      * @return $this
353 353
      */
354
-    public function setOption ($option, $value) {
354
+    public function setOption($option, $value) {
355 355
         if (!@socket_set_option($this->resource, SOL_SOCKET, $option, $value)) {
356 356
             throw new Error($this->resource, SOCKET_EINVAL);
357 357
         }
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
      * @throws Error
366 366
      * @return $this
367 367
      */
368
-    public function setTimeout ($timeout) {
368
+    public function setTimeout($timeout) {
369 369
         $timeval = ['sec' => (int)$timeout, 'usec' => (int)(fmod($timeout, 1) * 1000000)];
370 370
         $this->setOption(SO_RCVTIMEO, $timeval);
371 371
         $this->setOption(SO_SNDTIMEO, $timeval);
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
      * @throws Error
393 393
      * @return $this
394 394
      */
395
-    public function shutdown ($channel) {
395
+    public function shutdown($channel) {
396 396
         $this->onShutdown($channel);
397 397
         if (!@socket_shutdown($this->resource, $channel)) {
398 398
             throw new Error($this->resource); // reliable errno
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -96,11 +96,9 @@  discard block
 block discarded – undo
96 96
     public function __construct ($resource) {
97 97
         if (!is_resource($resource) or get_resource_type($resource) !== 'Socket') {
98 98
             throw new InvalidArgumentException('Expected an open socket resource.', SOCKET_EBADF);
99
-        }
100
-        elseif (socket_get_option($resource, SOL_SOCKET, SO_TYPE) !== static::getType()) {
99
+        } elseif (socket_get_option($resource, SOL_SOCKET, SO_TYPE) !== static::getType()) {
101 100
             throw new InvalidArgumentException('The given socket resource is of the wrong type for ' . get_class(), SOCKET_ESOCKTNOSUPPORT);
102
-        }
103
-        elseif ($errno = Error::getLast($resource)) {
101
+        } elseif ($errno = Error::getLast($resource)) {
104 102
             $error = new Error(SOCKET_EBADFD);
105 103
             $error->setExtra($errno);
106 104
             throw $error;
@@ -331,8 +329,7 @@  discard block
 block discarded – undo
331 329
     public function setBlocking ($blocking) {
332 330
         if ($blocking) {
333 331
             $success = @socket_set_block($this->resource);
334
-        }
335
-        else {
332
+        } else {
336 333
             $success = @socket_set_nonblock($this->resource);
337 334
         }
338 335
         if (!$success) {
Please login to merge, or discard this patch.
src/SocketInterface.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -42,40 +42,40 @@
 block discarded – undo
42 42
      *
43 43
      * @return int `AF_*`
44 44
      */
45
-    public function getDomain ();
45
+    public function getDomain();
46 46
 
47 47
     /**
48 48
      * Returns the underlying socket resource as an integer.
49 49
      *
50 50
      * @return int
51 51
      */
52
-    public function getId ();
52
+    public function getId();
53 53
 
54 54
     /**
55 55
      * Returns the protocol constant used by the socket.
56 56
      *
57 57
      * @return int
58 58
      */
59
-    public function getProtocol ();
59
+    public function getProtocol();
60 60
 
61 61
     /**
62 62
      * Returns the underlying socket resource.
63 63
      *
64 64
      * @return resource
65 65
      */
66
-    public function getResource ();
66
+    public function getResource();
67 67
 
68 68
     /**
69 69
      * Returns the socket type constant for the class.
70 70
      *
71 71
      * @return int `SOCK_*`
72 72
      */
73
-    public static function getType ();
73
+    public static function getType();
74 74
 
75 75
     /**
76 76
      * Whether the underlying resource is open.
77 77
      *
78 78
      * @return bool
79 79
      */
80
-    public function isOpen ();
80
+    public function isOpen();
81 81
 }
82 82
\ No newline at end of file
Please login to merge, or discard this patch.