Completed
Push — master ( 9fb81f...0a022c )
by y
01:28
created
src/AbstractSocket.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
      *
15 15
      * @return int
16 16
      */
17
-    abstract public static function getType (): int;
17
+    abstract public static function getType(): int;
18 18
 
19 19
     /**
20 20
      * The underlying PHP resource.
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
      * @return static
34 34
      * @throws SocketError
35 35
      */
36
-    public static function create (int $domain = AF_INET, ...$extra) {
36
+    public static function create(int $domain = AF_INET, ...$extra) {
37 37
         if (!$resource = @socket_create($domain, static::getType(), 0)) { // auto-protocol
38 38
             throw new SocketError; // reliable errno
39 39
         }
@@ -49,12 +49,12 @@  discard block
 block discarded – undo
49 49
      * @throws InvalidArgumentException Not a socket resource, or the socket is of the wrong type.
50 50
      * @throws SocketError Slippage of an existing error on the resource.
51 51
      */
52
-    public function __construct ($resource) {
52
+    public function __construct($resource) {
53 53
         if (!is_resource($resource) or get_resource_type($resource) !== 'Socket') {
54 54
             throw new InvalidArgumentException('Expected an open socket resource.', SOCKET_EBADF);
55 55
         }
56 56
         elseif (socket_get_option($resource, SOL_SOCKET, SO_TYPE) !== static::getType()) {
57
-            throw new InvalidArgumentException('Invalid socket type for ' . static::class, SOCKET_ESOCKTNOSUPPORT);
57
+            throw new InvalidArgumentException('Invalid socket type for '.static::class, SOCKET_ESOCKTNOSUPPORT);
58 58
         }
59 59
         elseif ($errno = SocketError::getLast($resource)) {
60 60
             // "File descriptor in bad state"
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
      *
69 69
      * @see close()
70 70
      */
71
-    public function __destruct () {
71
+    public function __destruct() {
72 72
         if ($this->isOpen()) {
73 73
             $this->close();
74 74
         }
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
      * @return $this
86 86
      * @throws SocketError
87 87
      */
88
-    public function await (int $channel) {
88
+    public function await(int $channel) {
89 89
         $rwe = [$channel => [$this->resource]];
90 90
         if (!@socket_select($rwe[0], $rwe[1], $rwe[2], null)) {
91 91
             throw new SocketError($this->resource);
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
      *
99 99
      * @return $this
100 100
      */
101
-    final public function awaitOutOfBand () {
101
+    final public function awaitOutOfBand() {
102 102
         return $this->await(self::CH_EXCEPT);
103 103
     }
104 104
 
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
      *
108 108
      * @return $this
109 109
      */
110
-    final public function awaitReadable () {
110
+    final public function awaitReadable() {
111 111
         return $this->await(self::CH_READ);
112 112
     }
113 113
 
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
      *
117 117
      * @return $this
118 118
      */
119
-    final public function awaitWritable () {
119
+    final public function awaitWritable() {
120 120
         return $this->await(self::CH_WRITE);
121 121
     }
122 122
 
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
      *
130 130
      * @return $this
131 131
      */
132
-    public function close () {
132
+    public function close() {
133 133
         socket_close($this->resource);
134 134
         return $this;
135 135
     }
@@ -139,15 +139,15 @@  discard block
 block discarded – undo
139 139
      *
140 140
      * @return int
141 141
      */
142
-    final public function getDomain (): int {
142
+    final public function getDomain(): int {
143 143
         return $this->getOption(39); // SO_DOMAIN is not exposed by PHP
144 144
     }
145 145
 
146 146
     /**
147 147
      * @return int
148 148
      */
149
-    final public function getId (): int {
150
-        return (int)$this->resource;
149
+    final public function getId(): int {
150
+        return (int) $this->resource;
151 151
     }
152 152
 
153 153
     /**
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
      * @return mixed The option's value. This is never `false`.
160 160
      * @throws SocketError
161 161
      */
162
-    public function getOption (int $option) {
162
+    public function getOption(int $option) {
163 163
         $value = @socket_get_option($this->resource, SOL_SOCKET, $option);
164 164
         if ($value === false) {
165 165
             throw new SocketError($this->resource, SOCKET_EINVAL);
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
     /**
171 171
      * @return resource
172 172
      */
173
-    final public function getResource () {
173
+    final public function getResource() {
174 174
         return $this->resource;
175 175
     }
176 176
 
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
      * @return array `[ 0 => address, 1 => port ]`
183 183
      * @throws SocketError
184 184
      */
185
-    public function getSockName (): array {
185
+    public function getSockName(): array {
186 186
         if (!@socket_getsockname($this->resource, $addr, $port)) {
187 187
             throw new SocketError($this->resource, SOCKET_EOPNOTSUPP);
188 188
         }
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
     /**
193 193
      * @return bool
194 194
      */
195
-    public function isOpen (): bool {
195
+    public function isOpen(): bool {
196 196
         return is_resource($this->resource);
197 197
     }
198 198
 
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
      *
204 204
      * @return bool
205 205
      */
206
-    final public function isOutOfBand (): bool {
206
+    final public function isOutOfBand(): bool {
207 207
         return $this->isReady(self::CH_EXCEPT);
208 208
     }
209 209
 
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
      *
215 215
      * @return bool
216 216
      */
217
-    final public function isReadable (): bool {
217
+    final public function isReadable(): bool {
218 218
         return $this->isReady(self::CH_READ);
219 219
     }
220 220
 
@@ -228,15 +228,15 @@  discard block
 block discarded – undo
228 228
      * @return bool
229 229
      * @throws SocketError
230 230
      */
231
-    public function isReady (int $channel, ?float $timeout = 0): bool {
231
+    public function isReady(int $channel, ?float $timeout = 0): bool {
232 232
         $rwe = [$channel => [$this->resource]];
233 233
         // core casts non-null timeout to int.
234 234
         // usec is ignored if timeout is null.
235
-        $usec = (int)(fmod($timeout, 1) * 1000000);
235
+        $usec = (int) (fmod($timeout, 1) * 1000000);
236 236
         if (false === $count = @socket_select($rwe[0], $rwe[1], $rwe[2], $timeout, $usec)) {
237 237
             throw new SocketError($this->resource);
238 238
         }
239
-        return (bool)$count;
239
+        return (bool) $count;
240 240
     }
241 241
 
242 242
     /**
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
      *
247 247
      * @return bool
248 248
      */
249
-    final public function isWritable (): bool {
249
+    final public function isWritable(): bool {
250 250
         return $this->isReady(self::CH_WRITE);
251 251
     }
252 252
 
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
      * @return $this
271 271
      * @throws SocketError
272 272
      */
273
-    public function setBlocking (bool $blocking) {
273
+    public function setBlocking(bool $blocking) {
274 274
         if ($blocking ? @socket_set_block($this->resource) : @socket_set_nonblock($this->resource)) {
275 275
             return $this;
276 276
         }
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
      * @return $this
288 288
      * @throws SocketError
289 289
      */
290
-    public function setOption (int $option, $value) {
290
+    public function setOption(int $option, $value) {
291 291
         if (!@socket_set_option($this->resource, SOL_SOCKET, $option, $value)) {
292 292
             throw new SocketError($this->resource, SOCKET_EINVAL);
293 293
         }
@@ -300,10 +300,10 @@  discard block
 block discarded – undo
300 300
      * @param float $timeout Zero means "no timeout" (block forever).
301 301
      * @return $this
302 302
      */
303
-    public function setTimeout (float $timeout) {
303
+    public function setTimeout(float $timeout) {
304 304
         $tv = [
305
-            'sec' => (int)$timeout,
306
-            'usec' => (int)(fmod($timeout, 1) * 1000000)
305
+            'sec' => (int) $timeout,
306
+            'usec' => (int) (fmod($timeout, 1) * 1000000)
307 307
         ];
308 308
         $this->setOption(SO_RCVTIMEO, $tv);
309 309
         $this->setOption(SO_SNDTIMEO, $tv);
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
      * @return $this
334 334
      * @throws SocketError
335 335
      */
336
-    public function shutdown (int $channel) {
336
+    public function shutdown(int $channel) {
337 337
         if (!@socket_shutdown($this->resource, $channel)) {
338 338
             throw new SocketError($this->resource); // reliable errno
339 339
         }
Please login to merge, or discard this patch.
src/WebSocket/WebSocketClient.php 2 patches
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
      * @param resource $resource
58 58
      * @param WebSocketServer $server
59 59
      */
60
-    public function __construct ($resource, WebSocketServer $server) {
60
+    public function __construct($resource, WebSocketServer $server) {
61 61
         parent::__construct($resource);
62 62
         $this->server = $server;
63 63
         $this->handshake = new HandShake($this);
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
      * @param string $reason Sent to the peer, if code is >= 1000
84 84
      * @return $this
85 85
      */
86
-    public function close (int $code = null, string $reason = '') {
86
+    public function close(int $code = null, string $reason = '') {
87 87
         try {
88 88
             if ($code >= 1000 and $this->isOk()) {
89 89
                 $this->frameHandler->writeClose($code, $reason);
@@ -100,35 +100,35 @@  discard block
 block discarded – undo
100 100
     /**
101 101
      * @return FrameHandler
102 102
      */
103
-    public function getFrameHandler (): FrameHandler {
103
+    public function getFrameHandler(): FrameHandler {
104 104
         return $this->frameHandler;
105 105
     }
106 106
 
107 107
     /**
108 108
      * @return HandShake
109 109
      */
110
-    public function getHandshake (): HandShake {
110
+    public function getHandshake(): HandShake {
111 111
         return $this->handshake;
112 112
     }
113 113
 
114 114
     /**
115 115
      * @return WebSocketServer
116 116
      */
117
-    public function getServer (): WebSocketServer {
117
+    public function getServer(): WebSocketServer {
118 118
         return $this->server;
119 119
     }
120 120
 
121 121
     /**
122 122
      * @return int
123 123
      */
124
-    public function getState (): int {
124
+    public function getState(): int {
125 125
         return $this->state;
126 126
     }
127 127
 
128 128
     /**
129 129
      * @return bool
130 130
      */
131
-    final public function isOk (): bool {
131
+    final public function isOk(): bool {
132 132
         return $this->state === self::STATE_OK;
133 133
     }
134 134
 
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
      * @param string $binary
141 141
      * @throws WebSocketError
142 142
      */
143
-    public function onBinary (string $binary): void {
143
+    public function onBinary(string $binary): void {
144 144
         unset($binary);
145 145
         throw new WebSocketError(Frame::CLOSE_UNHANDLED_DATA, "I don't handle binary data.");
146 146
     }
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
      * @param int $code
152 152
      * @param string $reason
153 153
      */
154
-    public function onClose (int $code, string $reason): void {
154
+    public function onClose(int $code, string $reason): void {
155 155
         unset($code, $reason);
156 156
         $this->close();
157 157
     }
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
      *
164 164
      * Closes the connection with a protocol-error frame.
165 165
      */
166
-    final public function onOutOfBand (): void {
166
+    final public function onOutOfBand(): void {
167 167
         $this->close(Frame::CLOSE_PROTOCOL_ERROR, "Received out-of-band data.");
168 168
     }
169 169
 
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
      *
175 175
      * @param string $message
176 176
      */
177
-    public function onPing (string $message): void {
177
+    public function onPing(string $message): void {
178 178
         $this->frameHandler->writePong($message);
179 179
     }
180 180
 
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
      *
186 186
      * @param string $message
187 187
      */
188
-    public function onPong (string $message): void {
188
+    public function onPong(string $message): void {
189 189
         // stub
190 190
     }
191 191
 
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
      * @throws WebSocketError
196 196
      * @throws Throwable
197 197
      */
198
-    public function onReadable (): void {
198
+    public function onReadable(): void {
199 199
         if (!strlen($this->recv(1, MSG_PEEK))) { // peer has shut down writing, or closed.
200 200
             $this->close();
201 201
             return;
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
      *
233 233
      * Does nothing by default.
234 234
      */
235
-    protected function onStateOk (): void {
235
+    protected function onStateOk(): void {
236 236
         // stub
237 237
     }
238 238
 
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
      * @param string $text
245 245
      * @throws WebSocketError
246 246
      */
247
-    public function onText (string $text): void {
247
+    public function onText(string $text): void {
248 248
         unset($text);
249 249
         throw new WebSocketError(Frame::CLOSE_UNHANDLED_DATA, "I don't handle text.");
250 250
     }
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
      *
255 255
      * @param string $binary
256 256
      */
257
-    public function writeBinary (string $binary): void {
257
+    public function writeBinary(string $binary): void {
258 258
         $this->frameHandler->writeBinary($binary);
259 259
     }
260 260
 
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
      *
264 264
      * @param string $text
265 265
      */
266
-    public function writeText (string $text): void {
266
+    public function writeText(string $text): void {
267 267
         $this->frameHandler->writeText($text);
268 268
     }
269 269
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -88,8 +88,7 @@  discard block
 block discarded – undo
88 88
             if ($code >= 1000 and $this->isOk()) {
89 89
                 $this->frameHandler->writeClose($code, $reason);
90 90
             }
91
-        }
92
-        finally {
91
+        } finally {
93 92
             $this->server->remove($this);
94 93
             parent::close();
95 94
             $this->state = self::STATE_CLOSED;
@@ -216,12 +215,10 @@  discard block
 block discarded – undo
216 215
                 case self::STATE_CLOSED:
217 216
                     return;
218 217
             }
219
-        }
220
-        catch (WebSocketError $e) {
218
+        } catch (WebSocketError $e) {
221 219
             $this->close($e->getCode(), $e->getMessage());
222 220
             throw $e;
223
-        }
224
-        catch (Throwable $e) {
221
+        } catch (Throwable $e) {
225 222
             $this->close(Frame::CLOSE_INTERNAL_ERROR);
226 223
             throw $e;
227 224
         }
Please login to merge, or discard this patch.
src/WebSocket/FrameHandler.php 2 patches
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -51,21 +51,21 @@  discard block
 block discarded – undo
51 51
     /**
52 52
      * @param WebSocketClient $client
53 53
      */
54
-    public function __construct (WebSocketClient $client) {
54
+    public function __construct(WebSocketClient $client) {
55 55
         $this->client = $client;
56 56
     }
57 57
 
58 58
     /**
59 59
      * @return int
60 60
      */
61
-    public function getFragmentSize (): int {
61
+    public function getFragmentSize(): int {
62 62
         return $this->fragmentSize;
63 63
     }
64 64
 
65 65
     /**
66 66
      * @return int
67 67
      */
68
-    public function getMaxLength (): int {
68
+    public function getMaxLength(): int {
69 69
         return $this->maxLength;
70 70
     }
71 71
 
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
      * @param Frame $frame
77 77
      * @throws WebSocketError
78 78
      */
79
-    protected function onBinary (Frame $frame): void {
79
+    protected function onBinary(Frame $frame): void {
80 80
         $this->buffer .= $frame->getPayload();
81 81
         if ($frame->isFinal()) {
82 82
             $binary = $this->buffer;
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
      *
97 97
      * @param Frame $frame
98 98
      */
99
-    protected function onClose (Frame $frame): void {
99
+    protected function onClose(Frame $frame): void {
100 100
         $this->client->onClose($frame->getCloseCode(), $frame->getCloseReason());
101 101
     }
102 102
 
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
      * @param Frame $frame
107 107
      * @throws WebSocketError
108 108
      */
109
-    protected function onContinue (Frame $frame): void {
109
+    protected function onContinue(Frame $frame): void {
110 110
         if (!$this->continue) {
111 111
             throw new WebSocketError(
112 112
                 Frame::CLOSE_PROTOCOL_ERROR,
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
      *
139 139
      * @param Frame $frame
140 140
      */
141
-    protected function onControl (Frame $frame): void {
141
+    protected function onControl(Frame $frame): void {
142 142
         if ($frame->isClose()) {
143 143
             $this->onClose($frame);
144 144
         }
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
      *
159 159
      * @param Frame $frame
160 160
      */
161
-    protected function onData (Frame $frame): void {
161
+    protected function onData(Frame $frame): void {
162 162
         $this->onData_SetContinue($frame);
163 163
         if ($frame->isText()) {
164 164
             $this->onText($frame);
@@ -174,11 +174,11 @@  discard block
 block discarded – undo
174 174
      * @param Frame $frame
175 175
      * @throws WebSocketError
176 176
      */
177
-    protected function onData_SetContinue (Frame $frame): void {
177
+    protected function onData_SetContinue(Frame $frame): void {
178 178
         if ($this->continue) {
179 179
             throw new WebSocketError(
180 180
                 Frame::CLOSE_PROTOCOL_ERROR,
181
-                "Received interleaved {$frame->getName()} against existing " . Frame::NAMES[$this->continue],
181
+                "Received interleaved {$frame->getName()} against existing ".Frame::NAMES[$this->continue],
182 182
                 $frame
183 183
             );
184 184
         }
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
      *
197 197
      * @param Frame $frame
198 198
      */
199
-    public function onFrame (Frame $frame): void {
199
+    public function onFrame(Frame $frame): void {
200 200
         $this->onFrame_CheckRsv($frame);
201 201
         $this->onFrame_CheckLength($frame);
202 202
         if ($frame->isControl()) {
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
      * @param Frame $frame
217 217
      * @throws WebSocketError
218 218
      */
219
-    protected function onFrame_CheckLength (Frame $frame): void {
219
+    protected function onFrame_CheckLength(Frame $frame): void {
220 220
         if ($frame->isData()) {
221 221
             $length = strlen($this->buffer);
222 222
             if ($length + $frame->getLength() > $this->maxLength) {
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
      * @param Frame $frame
236 236
      * @throws WebSocketError
237 237
      */
238
-    protected function onFrame_CheckRsv (Frame $frame): void {
238
+    protected function onFrame_CheckRsv(Frame $frame): void {
239 239
         if ($badRsv = $frame->getRsv() & ~$this->client->getHandshake()->getRsv()) {
240 240
             $badRsv = str_pad(base_convert($badRsv >> 4, 10, 2), 3, '0', STR_PAD_LEFT);
241 241
             throw new WebSocketError(
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
      *
252 252
      * @param Frame $frame
253 253
      */
254
-    protected function onPing (Frame $frame): void {
254
+    protected function onPing(Frame $frame): void {
255 255
         $this->client->onPing($frame->getPayload());
256 256
     }
257 257
 
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
      *
261 261
      * @param Frame $frame
262 262
      */
263
-    protected function onPong (Frame $frame): void {
263
+    protected function onPong(Frame $frame): void {
264 264
         $this->client->onPong($frame->getPayload());
265 265
     }
266 266
 
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
      * @param Frame $frame
272 272
      * @throws WebSocketError
273 273
      */
274
-    protected function onText (Frame $frame): void {
274
+    protected function onText(Frame $frame): void {
275 275
         $this->buffer .= $frame->getPayload();
276 276
         if ($frame->isFinal()) {
277 277
             if (!mb_detect_encoding($this->buffer, 'UTF-8', true)) {
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
      * @param int $bytes
288 288
      * @return $this
289 289
      */
290
-    public function setFragmentSize (int $bytes) {
290
+    public function setFragmentSize(int $bytes) {
291 291
         $this->fragmentSize = $bytes;
292 292
         return $this;
293 293
     }
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
      * @param int $bytes
297 297
      * @return $this
298 298
      */
299
-    public function setMaxLength (int $bytes) {
299
+    public function setMaxLength(int $bytes) {
300 300
         $this->maxLength = $bytes;
301 301
         return $this;
302 302
     }
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
      * @param int $opCode
308 308
      * @param string $payload
309 309
      */
310
-    public function write (int $opCode, string $payload): void {
310
+    public function write(int $opCode, string $payload): void {
311 311
         $offset = 0;
312 312
         $total = strlen($payload);
313 313
         do {
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
     /**
324 324
      * @param string $payload
325 325
      */
326
-    public function writeBinary (string $payload): void {
326
+    public function writeBinary(string $payload): void {
327 327
         $this->write(Frame::OP_BINARY, $payload);
328 328
     }
329 329
 
@@ -331,8 +331,8 @@  discard block
 block discarded – undo
331 331
      * @param int $code
332 332
      * @param string $reason
333 333
      */
334
-    public function writeClose (int $code = Frame::CLOSE_NORMAL, string $reason = ''): void {
335
-        $this->writeFrame(true, Frame::OP_CLOSE, pack('n', $code) . $reason);
334
+    public function writeClose(int $code = Frame::CLOSE_NORMAL, string $reason = ''): void {
335
+        $this->writeFrame(true, Frame::OP_CLOSE, pack('n', $code).$reason);
336 336
     }
337 337
 
338 338
     /**
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
      * @param int $opCode
343 343
      * @param string $payload
344 344
      */
345
-    protected function writeFrame (bool $final, int $opCode, string $payload): void {
345
+    protected function writeFrame(bool $final, int $opCode, string $payload): void {
346 346
         if ($opCode & 0x08 and !$final) {
347 347
             throw new LogicException("Would have sent a fragmented control frame ({$opCode}) {$payload}");
348 348
         }
@@ -359,27 +359,27 @@  discard block
 block discarded – undo
359 359
         else {
360 360
             $head .= chr($length);
361 361
         }
362
-        $this->client->write($head . $payload);
362
+        $this->client->write($head.$payload);
363 363
     }
364 364
 
365 365
     /**
366 366
      * @param string $payload
367 367
      */
368
-    public function writePing (string $payload = ''): void {
368
+    public function writePing(string $payload = ''): void {
369 369
         $this->writeFrame(true, Frame::OP_PING, $payload);
370 370
     }
371 371
 
372 372
     /**
373 373
      * @param string $payload
374 374
      */
375
-    public function writePong (string $payload = ''): void {
375
+    public function writePong(string $payload = ''): void {
376 376
         $this->writeFrame(true, Frame::OP_PONG, $payload);
377 377
     }
378 378
 
379 379
     /**
380 380
      * @param string $payload
381 381
      */
382
-    public function writeText (string $payload): void {
382
+    public function writeText(string $payload): void {
383 383
         $this->write(Frame::OP_TEXT, $payload);
384 384
     }
385 385
 }
386 386
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +10 added lines, -20 removed lines patch added patch discarded remove patch
@@ -117,12 +117,10 @@  discard block
 block discarded – undo
117 117
         try {
118 118
             if ($this->continue === Frame::OP_TEXT) {
119 119
                 $this->onText($frame);
120
-            }
121
-            else {
120
+            } else {
122 121
                 $this->onBinary($frame);
123 122
             }
124
-        }
125
-        finally {
123
+        } finally {
126 124
             if ($frame->isFinal()) {
127 125
                 $this->continue = null;
128 126
             }
@@ -141,14 +139,11 @@  discard block
 block discarded – undo
141 139
     protected function onControl (Frame $frame): void {
142 140
         if ($frame->isClose()) {
143 141
             $this->onClose($frame);
144
-        }
145
-        elseif ($frame->isPing()) {
142
+        } elseif ($frame->isPing()) {
146 143
             $this->onPing($frame);
147
-        }
148
-        elseif ($frame->isPong()) {
144
+        } elseif ($frame->isPong()) {
149 145
             $this->onPong($frame);
150
-        }
151
-        else {
146
+        } else {
152 147
             throw new WebSocketError(Frame::CLOSE_PROTOCOL_ERROR, "Unsupported control frame.", $frame);
153 148
         }
154 149
     }
@@ -162,8 +157,7 @@  discard block
 block discarded – undo
162 157
         $this->onData_SetContinue($frame);
163 158
         if ($frame->isText()) {
164 159
             $this->onText($frame);
165
-        }
166
-        elseif ($frame->isBinary()) {
160
+        } elseif ($frame->isBinary()) {
167 161
             $this->onBinary($frame);
168 162
         }
169 163
     }
@@ -201,11 +195,9 @@  discard block
 block discarded – undo
201 195
         $this->onFrame_CheckLength($frame);
202 196
         if ($frame->isControl()) {
203 197
             $this->onControl($frame);
204
-        }
205
-        elseif ($frame->isContinue()) {
198
+        } elseif ($frame->isContinue()) {
206 199
             $this->onContinue($frame);
207
-        }
208
-        else {
200
+        } else {
209 201
             $this->onData($frame);
210 202
         }
211 203
     }
@@ -351,12 +343,10 @@  discard block
 block discarded – undo
351 343
         if ($length > 65535) {
352 344
             $head .= chr(127);
353 345
             $head .= pack('J', $length);
354
-        }
355
-        elseif ($length >= 126) {
346
+        } elseif ($length >= 126) {
356 347
             $head .= chr(126);
357 348
             $head .= pack('n', $length);
358
-        }
359
-        else {
349
+        } else {
360 350
             $head .= chr($length);
361 351
         }
362 352
         $this->client->write($head . $payload);
Please login to merge, or discard this patch.
src/WebSocket/WebSocketServer.php 2 patches
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
      * @param $resource
32 32
      * @param Reactor $reactor
33 33
      */
34
-    public function __construct ($resource, Reactor $reactor) {
34
+    public function __construct($resource, Reactor $reactor) {
35 35
         parent::__construct($resource);
36 36
         $reactor->add($this);
37 37
         $this->reactor = $reactor;
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
     /**
41 41
      * @return WebSocketClient
42 42
      */
43
-    public function accept (): WebSocketClient {
43
+    public function accept(): WebSocketClient {
44 44
         /**
45 45
          * @see newClient()
46 46
          * @var WebSocketClient $client
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
      * @param int $opCode
58 58
      * @param string $payload
59 59
      */
60
-    public function broadcast (int $opCode, string $payload) {
60
+    public function broadcast(int $opCode, string $payload) {
61 61
         foreach ($this->clients as $client) {
62 62
             if ($client->isOk()) {
63 63
                 $client->getFrameHandler()->write($opCode, $payload);
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
     /**
69 69
      * @param string $payload
70 70
      */
71
-    public function broadcastBinary (string $payload) {
71
+    public function broadcastBinary(string $payload) {
72 72
         $this->broadcast(Frame::OP_BINARY, $payload);
73 73
     }
74 74
 
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
      *
78 78
      * @param string $payload
79 79
      */
80
-    public function broadcastPing (string $payload = '') {
80
+    public function broadcastPing(string $payload = '') {
81 81
         $this->broadcast(Frame::OP_PING, $payload);
82 82
     }
83 83
 
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
      *
87 87
      * @param string $text
88 88
      */
89
-    public function broadcastText (string $text) {
89
+    public function broadcastText(string $text) {
90 90
         $this->broadcast(Frame::OP_TEXT, $text);
91 91
     }
92 92
 
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
      * @param string $reason
98 98
      * @return $this
99 99
      */
100
-    public function close (int $code = Frame::CLOSE_INTERRUPT, $reason = '') {
100
+    public function close(int $code = Frame::CLOSE_INTERRUPT, $reason = '') {
101 101
         foreach ($this->clients as $client) {
102 102
             try {
103 103
                 $client->close($code, $reason); // clients remove themselves
@@ -115,14 +115,14 @@  discard block
 block discarded – undo
115 115
      *
116 116
      * @return int
117 117
      */
118
-    public function count (): int {
118
+    public function count(): int {
119 119
         return count($this->clients);
120 120
     }
121 121
 
122 122
     /**
123 123
      * @return WebSocketClient[]
124 124
      */
125
-    public function getClients () {
125
+    public function getClients() {
126 126
         return $this->clients;
127 127
     }
128 128
 
@@ -130,21 +130,21 @@  discard block
 block discarded – undo
130 130
      * @param resource $resource
131 131
      * @return WebSocketClient
132 132
      */
133
-    protected function newClient ($resource): WebSocketClient {
133
+    protected function newClient($resource): WebSocketClient {
134 134
         return new WebSocketClient($resource, $this);
135 135
     }
136 136
 
137 137
     /**
138 138
      * WebSocket servers never get OOB data.
139 139
      */
140
-    final public function onOutOfBand (): void {
140
+    final public function onOutOfBand(): void {
141 141
         // do nothing
142 142
     }
143 143
 
144 144
     /**
145 145
      * Auto-accept.
146 146
      */
147
-    public function onReadable (): void {
147
+    public function onReadable(): void {
148 148
         $this->accept();
149 149
     }
150 150
 
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
      *
154 154
      * @param WebSocketClient $client
155 155
      */
156
-    public function remove ($client): void {
156
+    public function remove($client): void {
157 157
         unset($this->clients[$client->getId()]);
158 158
         $this->reactor->remove($client);
159 159
     }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -101,8 +101,7 @@
 block discarded – undo
101 101
         foreach ($this->clients as $client) {
102 102
             try {
103 103
                 $client->close($code, $reason); // clients remove themselves
104
-            }
105
-            catch (Exception $e) {
104
+            } catch (Exception $e) {
106 105
                 continue;
107 106
             }
108 107
         }
Please login to merge, or discard this patch.
src/Reactor.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -31,12 +31,12 @@  discard block
 block discarded – undo
31 31
      * @return int
32 32
      * @throws SocketError
33 33
      */
34
-    public static function select (array &$read, array &$write, array &$except, ?float $timeout = null): int {
34
+    public static function select(array &$read, array &$write, array &$except, ?float $timeout = null): int {
35 35
         $rwe = [$read, $write, $except];
36 36
         array_walk_recursive($rwe, function(SocketInterface &$each) {
37 37
             $each = $each->getResource();
38 38
         });
39
-        $uSec = (int)(fmod($timeout, 1) * 1000000); // ignored if timeout is null
39
+        $uSec = (int) (fmod($timeout, 1) * 1000000); // ignored if timeout is null
40 40
         $count = @socket_select($rwe[0], $rwe[1], $rwe[2], $timeout, $uSec); // keys are preserved
41 41
         if ($count === false) {
42 42
             $read = $write = $except = [];
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
      * @param ReactiveInterface $socket
55 55
      * @return $this
56 56
      */
57
-    public function add (ReactiveInterface $socket) {
57
+    public function add(ReactiveInterface $socket) {
58 58
         $this->sockets[$socket->getId()] = $socket;
59 59
         return $this;
60 60
     }
@@ -64,14 +64,14 @@  discard block
 block discarded – undo
64 64
      *
65 65
      * @return int
66 66
      */
67
-    public function count (): int {
67
+    public function count(): int {
68 68
         return count($this->sockets);
69 69
     }
70 70
 
71 71
     /**
72 72
      * @return ReactiveInterface[]
73 73
      */
74
-    public function getSockets () {
74
+    public function getSockets() {
75 75
         return $this->sockets;
76 76
     }
77 77
 
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
      * @param ReactiveInterface $socket
81 81
      * @param Throwable $error
82 82
      */
83
-    public function onError (int $channel, $socket, Throwable $error): void {
83
+    public function onError(int $channel, $socket, Throwable $error): void {
84 84
         unset($channel);
85 85
         if ($socket instanceof WebSocketClient and $error instanceof WebSocketError) {
86 86
             $socket->close($error->getCode(), $error->getMessage());
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
      * @param float|null $timeout Maximum seconds to block. `NULL` blocks forever.
102 102
      * @return int Number of sockets selected.
103 103
      */
104
-    public function react (?float $timeout = null): int {
104
+    public function react(?float $timeout = null): int {
105 105
         /** @var ReactiveInterface[][] $rwe */
106 106
         $rwe = [$this->sockets, [], $this->sockets];
107 107
         $count = static::select($rwe[0], $rwe[1], $rwe[2], $timeout);
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
      * @param ReactiveInterface $socket
130 130
      * @return $this
131 131
      */
132
-    public function remove (ReactiveInterface $socket) {
132
+    public function remove(ReactiveInterface $socket) {
133 133
         unset($this->sockets[$socket->getId()]);
134 134
         return $this;
135 135
     }
Please login to merge, or discard this patch.