Passed
Push — master ( 3917c5...83603b )
by y
01:18
created
src/AbstractSocket.php 1 patch
Spacing   +29 added lines, -29 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,14 +66,14 @@  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
         $getResource = function(SocketInterface $socket) {
71 71
             return $socket->getResource();
72 72
         };
73 73
         // PHP 7.1 broke by-reference array_walk_recursive, use array_map instead.
74
-        $r = array_map($getResource,$read);
75
-        $w = array_map($getResource,$write);
76
-        $e = array_map($getResource,$except);
74
+        $r = array_map($getResource, $read);
75
+        $w = array_map($getResource, $write);
76
+        $e = array_map($getResource, $except);
77 77
         $usec = (int)(fmod($timeout, 1) * 1000000); // ignored if timeout is null
78 78
         $count = @socket_select($r, $w, $e, $timeout, $usec);
79 79
         if ($count === false) {
@@ -96,12 +96,12 @@  discard block
 block discarded – undo
96 96
      * @throws Error (`SOCKET_EBADFD`) There was a pending error on the socket, including `SO_ERROR`.
97 97
      * The existing error code is set in the extra data.
98 98
      */
99
-    public function __construct ($resource) {
99
+    public function __construct($resource) {
100 100
         if (!is_resource($resource) or get_resource_type($resource) !== 'Socket') {
101 101
             throw new InvalidArgumentException('Expected an open socket resource.', SOCKET_EBADF);
102 102
         }
103 103
         elseif (socket_get_option($resource, SOL_SOCKET, SO_TYPE) !== static::getType()) {
104
-            throw new InvalidArgumentException('The given socket resource is of the wrong type for ' . get_class(), SOCKET_ESOCKTNOSUPPORT);
104
+            throw new InvalidArgumentException('The given socket resource is of the wrong type for '.get_class(), SOCKET_ESOCKTNOSUPPORT);
105 105
         }
106 106
         elseif ($errno = Error::getLast($resource)) {
107 107
             $error = new Error(SOCKET_EBADFD);
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
     /**
117 117
      * Closes the socket if it's open.
118 118
      */
119
-    public function __destruct () {
119
+    public function __destruct() {
120 120
         $this->close();
121 121
     }
122 122
 
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
      * @return $this
132 132
      * @throws Error
133 133
      */
134
-    public function await ($channel) {
134
+    public function await($channel) {
135 135
         $select = [$channel => [$this->resource]];
136 136
         $count = @socket_select($select[self::CH_READ], $select[self::CH_WRITE], $select[self::CH_EXCEPT], null);
137 137
         if (!$count) {
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
      *
152 152
      * @return $this
153 153
      */
154
-    public function close () {
154
+    public function close() {
155 155
         // socket_close() never errors, but we guard anyway to prevent
156 156
         // a redundant call to onClose(), and an incorrect call to it if
157 157
         // the constructor failed and the destructor is calling this.
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
     /**
166 166
      * @return int
167 167
      */
168
-    final public function getDomain () {
168
+    final public function getDomain() {
169 169
         return $this->domain;
170 170
     }
171 171
 
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
      *
177 177
      * @return int
178 178
      */
179
-    final public function getId () {
179
+    final public function getId() {
180 180
         return (int)$this->resource;
181 181
     }
182 182
 
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
      * @throws Error The socket has no such option or is closed.
190 190
      * @return mixed The option's value. This is never `false`.
191 191
      */
192
-    public function getOption ($option) {
192
+    public function getOption($option) {
193 193
         $value = @socket_get_option($this->resource, SOL_SOCKET, $option);
194 194
         if ($value === false) {
195 195
             throw new Error($this->resource, SOCKET_EINVAL);
@@ -200,14 +200,14 @@  discard block
 block discarded – undo
200 200
     /**
201 201
      * @return int
202 202
      */
203
-    final public function getProtocol () {
203
+    final public function getProtocol() {
204 204
         return $this->protocol;
205 205
     }
206 206
 
207 207
     /**
208 208
      * @return resource
209 209
      */
210
-    final public function getResource () {
210
+    final public function getResource() {
211 211
         return $this->resource;
212 212
     }
213 213
 
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
      * @throws Error
220 220
      * @return array String address and integer port at indices `0` and `1`.
221 221
      */
222
-    public function getSockName () {
222
+    public function getSockName() {
223 223
         if (!@socket_getsockname($this->resource, $addr, $port)) {
224 224
             throw new Error($this->resource, SOCKET_EOPNOTSUPP);
225 225
         }
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
      * @return bool
235 235
      * @throws Error
236 236
      */
237
-    public function isExceptional () {
237
+    public function isExceptional() {
238 238
         return $this->isReady(self::CH_EXCEPT);
239 239
     }
240 240
 
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
      *
244 244
      * @return bool
245 245
      */
246
-    public function isOpen () {
246
+    public function isOpen() {
247 247
         return is_resource($this->resource);
248 248
     }
249 249
 
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
      * @return bool
256 256
      * @throws Error
257 257
      */
258
-    public function isReadable () {
258
+    public function isReadable() {
259 259
         return $this->isReady(self::CH_READ);
260 260
     }
261 261
 
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
      * @throws Error
270 270
      * @return bool
271 271
      */
272
-    public function isReady ($channel, $timeout = 0.0) {
272
+    public function isReady($channel, $timeout = 0.0) {
273 273
         $usec = (int)(fmod($timeout, 1) * 1000000); // ignored if timeout is null
274 274
         $select = [$channel => [$this->resource]];
275 275
         $count = $count = @socket_select($select[self::CH_READ], $select[self::CH_WRITE], $select[self::CH_EXCEPT], $timeout, $usec);
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
      * @return bool
288 288
      * @throws Error
289 289
      */
290
-    public function isWritable () {
290
+    public function isWritable() {
291 291
         return $this->isReady(self::CH_WRITE, 0);
292 292
     }
293 293
 
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
      *
297 297
      * @return void
298 298
      */
299
-    protected function onClose () { }
299
+    protected function onClose() { }
300 300
 
301 301
     /**
302 302
      * Stub. Called before an I/O channel is shut down.
@@ -304,14 +304,14 @@  discard block
 block discarded – undo
304 304
      * @param int $channel
305 305
      * @return void
306 306
      */
307
-    protected function onShutdown ($channel) { }
307
+    protected function onShutdown($channel) { }
308 308
 
309 309
     /**
310 310
      * Stub. Called when an I/O timeout has occurred, before it is thrown.
311 311
      *
312 312
      * @return void
313 313
      */
314
-    protected function onTimeout () { }
314
+    protected function onTimeout() { }
315 315
 
316 316
     /**
317 317
      * Enables or disables blocking.
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
      * @throws Error
332 332
      * @return $this
333 333
      */
334
-    public function setBlocking ($blocking) {
334
+    public function setBlocking($blocking) {
335 335
         if ($blocking) {
336 336
             $success = @socket_set_block($this->resource);
337 337
         }
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
      * @throws Error
355 355
      * @return $this
356 356
      */
357
-    public function setOption ($option, $value) {
357
+    public function setOption($option, $value) {
358 358
         if (!@socket_set_option($this->resource, SOL_SOCKET, $option, $value)) {
359 359
             throw new Error($this->resource, SOCKET_EINVAL);
360 360
         }
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
      * @throws Error
369 369
      * @return $this
370 370
      */
371
-    public function setTimeout ($timeout) {
371
+    public function setTimeout($timeout) {
372 372
         $timeval = ['sec' => (int)$timeout, 'usec' => (int)(fmod($timeout, 1) * 1000000)];
373 373
         $this->setOption(SO_RCVTIMEO, $timeval);
374 374
         $this->setOption(SO_SNDTIMEO, $timeval);
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
      * @throws Error
396 396
      * @return $this
397 397
      */
398
-    public function shutdown ($channel) {
398
+    public function shutdown($channel) {
399 399
         $this->onShutdown($channel);
400 400
         if (!@socket_shutdown($this->resource, $channel)) {
401 401
             throw new Error($this->resource); // reliable errno
Please login to merge, or discard this patch.