Passed
Push — master ( a91d54...875978 )
by y
02:08
created
src/AbstractSocket.php 2 patches
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
      * @return static
42 42
      * @throws SocketError
43 43
      */
44
-    public static function create ($domain = AF_INET, ...$extra) {
44
+    public static function create($domain = AF_INET, ...$extra) {
45 45
         if (!$resource = @socket_create($domain, static::getType(), 0)) { // auto-protocol
46 46
             throw new SocketError; // reliable errno
47 47
         }
@@ -58,12 +58,12 @@  discard block
 block discarded – undo
58 58
      * @throws SocketError (`SOCKET_EBADFD`) There was a pending error on the socket.
59 59
      * The preexisting error code is set as the exception's extra data.
60 60
      */
61
-    public function __construct ($resource) {
61
+    public function __construct($resource) {
62 62
         if (!is_resource($resource) or get_resource_type($resource) !== 'Socket') {
63 63
             throw new InvalidArgumentException('Expected an open socket resource.', SOCKET_EBADF);
64 64
         }
65 65
         elseif (socket_get_option($resource, SOL_SOCKET, SO_TYPE) !== static::getType()) {
66
-            throw new InvalidArgumentException('The given socket resource is of the wrong type for ' . get_class(), SOCKET_ESOCKTNOSUPPORT);
66
+            throw new InvalidArgumentException('The given socket resource is of the wrong type for '.get_class(), SOCKET_ESOCKTNOSUPPORT);
67 67
         }
68 68
         elseif ($errno = SocketError::getLast($resource)) {
69 69
             $error = new SocketError(SOCKET_EBADFD);
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
     /**
79 79
      * Closes the socket if it's open.
80 80
      */
81
-    public function __destruct () {
81
+    public function __destruct() {
82 82
         if ($this->isOpen()) {
83 83
             $this->close();
84 84
         }
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
      * @return $this
96 96
      * @throws SocketError
97 97
      */
98
-    public function await ($channel) {
98
+    public function await($channel) {
99 99
         $rwe = [$channel => [$this->resource]];
100 100
         if (!@socket_select($rwe[0], $rwe[1], $rwe[2], null)) {
101 101
             throw new SocketError($this->resource);
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
      *
109 109
      * @return $this
110 110
      */
111
-    final public function awaitOutOfBand () {
111
+    final public function awaitOutOfBand() {
112 112
         return $this->await(self::CH_EXCEPT);
113 113
     }
114 114
 
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
      *
118 118
      * @return $this
119 119
      */
120
-    final public function awaitReadable () {
120
+    final public function awaitReadable() {
121 121
         return $this->await(self::CH_READ);
122 122
     }
123 123
 
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
      *
127 127
      * @return $this
128 128
      */
129
-    final public function awaitWritable () {
129
+    final public function awaitWritable() {
130 130
         return $this->await(self::CH_WRITE);
131 131
     }
132 132
 
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
      *
138 138
      * @return $this
139 139
      */
140
-    public function close () {
140
+    public function close() {
141 141
         socket_close($this->resource); // never errors
142 142
         return $this;
143 143
     }
@@ -145,14 +145,14 @@  discard block
 block discarded – undo
145 145
     /**
146 146
      * @return int
147 147
      */
148
-    final public function getDomain (): int {
148
+    final public function getDomain(): int {
149 149
         return $this->domain;
150 150
     }
151 151
 
152 152
     /**
153 153
      * @return int
154 154
      */
155
-    final public function getId (): int {
155
+    final public function getId(): int {
156 156
         return (int)$this->resource;
157 157
     }
158 158
 
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
      * @throws SocketError
166 166
      * @return mixed The option's value. This is never `false`.
167 167
      */
168
-    public function getOption ($option) {
168
+    public function getOption($option) {
169 169
         $value = @socket_get_option($this->resource, SOL_SOCKET, $option);
170 170
         if ($value === false) {
171 171
             throw new SocketError($this->resource, SOCKET_EINVAL);
@@ -176,14 +176,14 @@  discard block
 block discarded – undo
176 176
     /**
177 177
      * @return int
178 178
      */
179
-    final public function getProtocol (): int {
179
+    final public function getProtocol(): int {
180 180
         return $this->protocol;
181 181
     }
182 182
 
183 183
     /**
184 184
      * @return resource
185 185
      */
186
-    final public function getResource () {
186
+    final public function getResource() {
187 187
         return $this->resource;
188 188
     }
189 189
 
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
      * @throws SocketError
196 196
      * @return array String address/file and integer port at indices `0` and `1`.
197 197
      */
198
-    public function getSockName () {
198
+    public function getSockName() {
199 199
         if (!@socket_getsockname($this->resource, $addr, $port)) {
200 200
             throw new SocketError($this->resource, SOCKET_EOPNOTSUPP);
201 201
         }
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
      *
208 208
      * @return bool
209 209
      */
210
-    public function isOpen (): bool {
210
+    public function isOpen(): bool {
211 211
         return is_resource($this->resource);
212 212
     }
213 213
 
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
      * @return bool
220 220
      * @throws SocketError
221 221
      */
222
-    public function isOutOfBand () {
222
+    public function isOutOfBand() {
223 223
         return $this->isReady(self::CH_EXCEPT);
224 224
     }
225 225
 
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
      * @return bool
232 232
      * @throws SocketError
233 233
      */
234
-    final public function isReadable () {
234
+    final public function isReadable() {
235 235
         return $this->isReady(self::CH_READ);
236 236
     }
237 237
 
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
      * @return bool
246 246
      * @throws SocketError
247 247
      */
248
-    public function isReady ($channel, $timeout = 0.0): bool {
248
+    public function isReady($channel, $timeout = 0.0): bool {
249 249
         $rwe = [$channel => [$this->resource]];
250 250
         // core casts non-null timeout to int.
251 251
         // usec is ignored if timeout is null.
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
      * @return bool
265 265
      * @throws SocketError
266 266
      */
267
-    final public function isWritable () {
267
+    final public function isWritable() {
268 268
         return $this->isReady(self::CH_WRITE);
269 269
     }
270 270
 
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
      * @throws SocketError
287 287
      * @return $this
288 288
      */
289
-    public function setBlocking ($blocking) {
289
+    public function setBlocking($blocking) {
290 290
         if ($blocking) {
291 291
             $success = @socket_set_block($this->resource);
292 292
         }
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
      * @throws SocketError
310 310
      * @return $this
311 311
      */
312
-    public function setOption ($option, $value) {
312
+    public function setOption($option, $value) {
313 313
         if (!@socket_set_option($this->resource, SOL_SOCKET, $option, $value)) {
314 314
             throw new SocketError($this->resource, SOCKET_EINVAL);
315 315
         }
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
      * @return $this
324 324
      * @throws SocketError
325 325
      */
326
-    public function setTimeout ($timeout) {
326
+    public function setTimeout($timeout) {
327 327
         $tv = [
328 328
             'sec' => (int)$timeout,
329 329
             'usec' => (int)(fmod($timeout, 1) * 1000000)
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
      * @throws SocketError
357 357
      * @return $this
358 358
      */
359
-    public function shutdown (int $channels = self::CH_READ | self::CH_WRITE) {
359
+    public function shutdown(int $channels = self::CH_READ | self::CH_WRITE) {
360 360
         if (!@socket_shutdown($this->resource, $channels)) {
361 361
             throw new SocketError($this->resource); // reliable errno
362 362
         }
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -61,11 +61,9 @@  discard block
 block discarded – undo
61 61
     public function __construct ($resource) {
62 62
         if (!is_resource($resource) or get_resource_type($resource) !== 'Socket') {
63 63
             throw new InvalidArgumentException('Expected an open socket resource.', SOCKET_EBADF);
64
-        }
65
-        elseif (socket_get_option($resource, SOL_SOCKET, SO_TYPE) !== static::getType()) {
64
+        } elseif (socket_get_option($resource, SOL_SOCKET, SO_TYPE) !== static::getType()) {
66 65
             throw new InvalidArgumentException('The given socket resource is of the wrong type for ' . get_class(), SOCKET_ESOCKTNOSUPPORT);
67
-        }
68
-        elseif ($errno = SocketError::getLast($resource)) {
66
+        } elseif ($errno = SocketError::getLast($resource)) {
69 67
             $error = new SocketError(SOCKET_EBADFD);
70 68
             $error->setExtra($errno);
71 69
             throw $error;
@@ -289,8 +287,7 @@  discard block
 block discarded – undo
289 287
     public function setBlocking ($blocking) {
290 288
         if ($blocking) {
291 289
             $success = @socket_set_block($this->resource);
292
-        }
293
-        else {
290
+        } else {
294 291
             $success = @socket_set_nonblock($this->resource);
295 292
         }
296 293
         if (!$success) {
Please login to merge, or discard this patch.
src/StreamClient.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
      *
13 13
      * @return int
14 14
      */
15
-    final public static function getType (): int {
15
+    final public static function getType(): int {
16 16
         return SOCK_STREAM;
17 17
     }
18 18
 
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
      * @return static[] Two instances at indices `0` and `1`.
27 27
      * @throws SocketError
28 28
      */
29
-    public static function newUnixPair (...$extra) {
29
+    public static function newUnixPair(...$extra) {
30 30
         if (!@socket_create_pair(AF_UNIX, SOCK_STREAM, 0, $fd)) {
31 31
             throw new SocketError; // reliable errno
32 32
         }
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
      * @return string
46 46
      * @throws SocketError The error's extra data is set to what was partially read.
47 47
      */
48
-    public function read ($length) {
48
+    public function read($length) {
49 49
         try {
50 50
             $data = '';
51 51
             do {
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
      * @throws SocketError
71 71
      * @return string
72 72
      */
73
-    public function recv ($length, $msgFlags = 0): string {
73
+    public function recv($length, $msgFlags = 0): string {
74 74
         if (false === @socket_recv($this->resource, $data, $length, $msgFlags)) {
75 75
             throw new SocketError($this->resource, SOCKET_EINVAL);
76 76
         }
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
      * @param int $msgFlags
86 86
      * @return string
87 87
      */
88
-    public function recvAll (int $msgFlags = 0): string {
88
+    public function recvAll(int $msgFlags = 0): string {
89 89
         $msgFlags = ($msgFlags & ~MSG_WAITALL) | MSG_DONTWAIT;
90 90
         $length = $this->getOption(SO_RCVBUF);
91 91
         try {
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -53,8 +53,7 @@  discard block
 block discarded – undo
53 53
                 $length -= $chunkSize = strlen($chunk);
54 54
             } while ($chunkSize and $length);
55 55
             return $data;
56
-        }
57
-        catch (SocketError $error) {
56
+        } catch (SocketError $error) {
58 57
             $error->setExtra($data);
59 58
             throw $error;
60 59
         }
@@ -90,8 +89,7 @@  discard block
 block discarded – undo
90 89
         $length = $this->getOption(SO_RCVBUF);
91 90
         try {
92 91
             return $this->recv($length, $msgFlags);
93
-        }
94
-        catch (SocketError $e) {
92
+        } catch (SocketError $e) {
95 93
             if ($e->getCode() === SOCKET_EAGAIN) { // would block
96 94
                 return '';
97 95
             }
Please login to merge, or discard this patch.
src/Reactor.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
      * @return int
29 29
      * @throws SocketError
30 30
      */
31
-    public static function select (array &$read, array &$write, array &$except, $timeout = null) {
31
+    public static function select(array &$read, array &$write, array &$except, $timeout = null) {
32 32
         $rwe = [$read, $write, $except];
33 33
         array_walk_recursive($rwe, function(SocketInterface &$each) {
34 34
             $each = $each->getResource();
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
      * @param ReactiveInterface $socket
52 52
      * @return $this
53 53
      */
54
-    public function add (ReactiveInterface $socket) {
54
+    public function add(ReactiveInterface $socket) {
55 55
         $this->sockets[$socket->getId()] = $socket;
56 56
         return $this;
57 57
     }
@@ -61,14 +61,14 @@  discard block
 block discarded – undo
61 61
      *
62 62
      * @return int
63 63
      */
64
-    public function count () {
64
+    public function count() {
65 65
         return count($this->sockets);
66 66
     }
67 67
 
68 68
     /**
69 69
      * @return SocketInterface[]
70 70
      */
71
-    public function getSockets () {
71
+    public function getSockets() {
72 72
         return $this->sockets;
73 73
     }
74 74
 
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
      * @param float|null $timeout Maximum seconds to block. `NULL` blocks forever.
83 83
      * @return int Number of sockets selected.
84 84
      */
85
-    public function react ($timeout = null) {
85
+    public function react($timeout = null) {
86 86
         /** @var ReactiveInterface[][] $rwe */
87 87
         $rwe = [$this->sockets, [], $this->sockets];
88 88
         $count = static::select($rwe[0], $rwe[1], $rwe[2], $timeout);
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
      * @param int|ReactiveInterface $id
111 111
      * @return $this
112 112
      */
113
-    public function remove ($id) {
113
+    public function remove($id) {
114 114
         unset($this->sockets[$id instanceof ReactiveInterface ? $id->getId() : $id]);
115 115
         return $this;
116 116
     }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -93,8 +93,7 @@
 block discarded – undo
93 93
             foreach ($rwe[0] as $id => $socket) {
94 94
                 $socket->onReadable();
95 95
             }
96
-        }
97
-        finally {
96
+        } finally {
98 97
             array_walk_recursive($rwe, function(ReactiveInterface $each) {
99 98
                 if (!$each->isOpen()) {
100 99
                     $this->remove($each);
Please login to merge, or discard this patch.
src/DatagramClient.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
      *
13 13
      * @return int
14 14
      */
15
-    final public static function getType (): int {
15
+    final public static function getType(): int {
16 16
         return SOCK_DGRAM;
17 17
     }
18 18
 
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
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
      *
17 17
      * @return string
18 18
      */
19
-    public function __toString () {
19
+    public function __toString() {
20 20
         try {
21 21
             return implode(':', $this->getSockName());
22 22
         }
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
      * @throws SocketError
39 39
      * @return $this
40 40
      */
41
-    public function bind (string $address, int $port = 0) {
41
+    public function bind(string $address, int $port = 0) {
42 42
         if (!@socket_bind($this->resource, $address, $port)) {
43 43
             throw new SocketError($this->resource, SOCKET_EOPNOTSUPP);
44 44
         }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -19,8 +19,7 @@
 block discarded – undo
19 19
     public function __toString () {
20 20
         try {
21 21
             return implode(':', $this->getSockName());
22
-        }
23
-        catch (Exception $exception) {
22
+        } catch (Exception $exception) {
24 23
             return ':';
25 24
         }
26 25
     }
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,41 +42,41 @@
 block discarded – undo
42 42
      *
43 43
      * @return int `SOCK_*`
44 44
      */
45
-    public static function getType (): int;
45
+    public static function getType(): int;
46 46
 
47 47
     /**
48 48
      * Returns the address family constant of the socket.
49 49
      *
50 50
      * @return int `AF_*`
51 51
      */
52
-    public function getDomain (): int;
52
+    public function getDomain(): int;
53 53
 
54 54
     /**
55 55
      * Returns the underlying socket resource as an integer.
56 56
      *
57 57
      * @return int
58 58
      */
59
-    public function getId (): int;
59
+    public function getId(): int;
60 60
 
61 61
     /**
62 62
      * Returns the protocol constant used by the socket.
63 63
      *
64 64
      * @return int
65 65
      */
66
-    public function getProtocol (): int;
66
+    public function getProtocol(): int;
67 67
 
68 68
     /**
69 69
      * Returns the underlying socket resource.
70 70
      *
71 71
      * @return resource
72 72
      */
73
-    public function getResource ();
73
+    public function getResource();
74 74
 
75 75
     /**
76 76
      * Whether the underlying resource is usable.
77 77
      *
78 78
      * @return bool
79 79
      */
80
-    public function isOpen (): bool;
80
+    public function isOpen(): bool;
81 81
 
82 82
 }
83 83
\ No newline at end of file
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
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
      *
13 13
      * @return int
14 14
      */
15
-    final public static function getType (): int {
15
+    final public static function getType(): int {
16 16
         return SOCK_DGRAM;
17 17
     }
18 18
 
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
      * @throws SocketError
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
             throw new SocketError($this->resource, SOCKET_EOPNOTSUPP);
Please login to merge, or discard this patch.
src/StreamServer.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
      *
13 13
      * @return int
14 14
      */
15
-    final public static function getType (): int {
15
+    final public static function getType(): int {
16 16
         return SOCK_STREAM;
17 17
     }
18 18
 
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
      * @throws SocketError
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 SocketError($this->resource); // reliable errno
31 31
         }
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
      * @throws SocketError
43 43
      * @return $this
44 44
      */
45
-    public function listen ($backlog = 0) {
45
+    public function listen($backlog = 0) {
46 46
         if (!@socket_listen($this->resource, $backlog)) {
47 47
             throw new SocketError($this->resource); // reliable errno
48 48
         }
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
      * @return StreamClient
57 57
      * @throws SocketError
58 58
      */
59
-    protected function newClient ($resource) {
59
+    protected function newClient($resource) {
60 60
         return new StreamClient($resource);
61 61
     }
62 62
 
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
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
      *
17 17
      * @return string
18 18
      */
19
-    public function __toString () {
19
+    public function __toString() {
20 20
         try {
21 21
             return implode(':', $this->getPeerName());
22 22
         }
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
      * @throws SocketError
41 41
      * @return $this
42 42
      */
43
-    public function connect ($address, $port = 0) {
43
+    public function connect($address, $port = 0) {
44 44
         if (!@socket_connect($this->resource, $address, $port)) {
45 45
             // ignore expected errors for non-blocking connections
46 46
             $errno = SocketError::getLast($this->resource);
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
      * @throws SocketError
61 61
      * @return array Address and port at indices `0` and `1`.
62 62
      */
63
-    public function getPeerName () {
63
+    public function getPeerName() {
64 64
         if ($this->domain === AF_UNIX) {
65 65
             return [$this->getOption(self::SO_PEERCRED), 0];
66 66
         }
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
      * @throws SocketError
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, strlen($data), $flags);
85 85
         if ($count === false) {
86 86
             throw new SocketError($this->resource); // reliable errno
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
      * @return $this
96 96
      * @throws SocketError Total bytes sent is set as the error's extra data.
97 97
      */
98
-    public function write ($data) {
98
+    public function write($data) {
99 99
         $data = (string)$data;
100 100
         $length = strlen($data);
101 101
         $total = 0;
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,8 +19,7 @@  discard block
 block discarded – undo
19 19
     public function __toString () {
20 20
         try {
21 21
             return implode(':', $this->getPeerName());
22
-        }
23
-        catch (Exception $exception) {
22
+        } catch (Exception $exception) {
24 23
             return ':';
25 24
         }
26 25
     }
@@ -102,8 +101,7 @@  discard block
 block discarded – undo
102 101
         while ($total < $length) {
103 102
             try {
104 103
                 $total += $this->awaitWritable()->send(substr($data, $total));
105
-            }
106
-            catch (SocketError $error) {
104
+            } catch (SocketError $error) {
107 105
                 $error->setExtra($total);
108 106
                 throw $error;
109 107
             }
Please login to merge, or discard this patch.