Completed
Push — master ( ec9c11...6665cb )
by y
01:14
created
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/ReactiveInterface.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -14,13 +14,13 @@
 block discarded – undo
14 14
      *
15 15
      * @return void
16 16
      */
17
-    public function onOutOfBand (): void;
17
+    public function onOutOfBand(): void;
18 18
 
19 19
     /**
20 20
      * Called by the reactor when the socket has readable data.
21 21
      *
22 22
      * @return void
23 23
      */
24
-    public function onReadable (): void;
24
+    public function onReadable(): void;
25 25
 
26 26
 }
27 27
\ No newline at end of file
Please login to merge, or discard this patch.
src/WebSocket/HandShake.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -45,32 +45,32 @@  discard block
 block discarded – undo
45 45
      */
46 46
     protected $sizeLimit = 4096;
47 47
 
48
-    public function __construct (WebSocketClient $client) {
48
+    public function __construct(WebSocketClient $client) {
49 49
         $this->client = $client;
50 50
     }
51 51
 
52 52
     /**
53 53
      * @return string[]
54 54
      */
55
-    public function getHeaders () {
55
+    public function getHeaders() {
56 56
         return $this->headers;
57 57
     }
58 58
 
59 59
     /**
60 60
      * @return string
61 61
      */
62
-    public function getMethod (): string {
62
+    public function getMethod(): string {
63 63
         return $this->method;
64 64
     }
65 65
 
66 66
     /**
67 67
      * @return int
68 68
      */
69
-    public function getRsv (): int {
69
+    public function getRsv(): int {
70 70
         return $this->rsv;
71 71
     }
72 72
 
73
-    public function negotiate (): bool {
73
+    public function negotiate(): bool {
74 74
         $this->buffer .= $this->client->recvAll();
75 75
         try {
76 76
             if (strlen($this->buffer) > $this->sizeLimit) {
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
                 $key = strtolower(trim($key));
91 91
                 $value = trim($value);
92 92
                 if (isset($this->headers[$key])) {
93
-                    $this->headers[$key] .= ', ' . $value;
93
+                    $this->headers[$key] .= ', '.$value;
94 94
                 }
95 95
                 else {
96 96
                     $this->headers[$key] = $value;
@@ -108,19 +108,19 @@  discard block
 block discarded – undo
108 108
         }
109 109
     }
110 110
 
111
-    protected function upgrade (): void {
111
+    protected function upgrade(): void {
112 112
         $this->client->write(implode("\r\n", [
113 113
             "HTTP/1.1 101 Switching Protocols",
114 114
             "Connection: Upgrade",
115 115
             "Upgrade: websocket",
116
-            "Sec-WebSocket-Accept: " . base64_encode(sha1($this->headers['sec-websocket-key'] . self::RFC_GUID, true)),
116
+            "Sec-WebSocket-Accept: ".base64_encode(sha1($this->headers['sec-websocket-key'].self::RFC_GUID, true)),
117 117
         ]));
118 118
     }
119 119
 
120 120
     /**
121 121
      * Validates the received HTTP handshake headers, or throws.
122 122
      */
123
-    protected function validate (): void {
123
+    protected function validate(): void {
124 124
         if (!(
125 125
             $check = 'method = http 1.1'
126 126
             and preg_match('/HTTP\/1\.1$/i', $this->method)
Please login to merge, or discard this patch.
src/WebSocket/WebSocketError.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
      */
26 26
     protected $frame;
27 27
 
28
-    public function __construct (int $code, string $message = '', Frame $frame = null, Throwable $previous = null) {
28
+    public function __construct(int $code, string $message = '', Frame $frame = null, Throwable $previous = null) {
29 29
         parent::__construct($message, $code, $previous);
30 30
         $this->frame = $frame;
31 31
     }
@@ -33,14 +33,14 @@  discard block
 block discarded – undo
33 33
     /**
34 34
      * @return mixed
35 35
      */
36
-    public function getExtra () {
36
+    public function getExtra() {
37 37
         return $this->extra;
38 38
     }
39 39
 
40 40
     /**
41 41
      * @return Frame|null
42 42
      */
43
-    public function getFrame () {
43
+    public function getFrame() {
44 44
         return $this->frame;
45 45
     }
46 46
 
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
      * @param mixed $extra
49 49
      * @return $this
50 50
      */
51
-    public function setExtra ($extra) {
51
+    public function setExtra($extra) {
52 52
         $this->extra = $extra;
53 53
         return $this;
54 54
     }
Please login to merge, or discard this patch.
src/AbstractClient.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
      *
19 19
      * @return string
20 20
      */
21
-    public function __toString () {
21
+    public function __toString() {
22 22
         try {
23 23
             return implode(':', $this->getPeerName());
24 24
         }
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
      * @return $this
42 42
      * @throws SocketError
43 43
      */
44
-    public function connect (string $address, int $port = 0) {
44
+    public function connect(string $address, int $port = 0) {
45 45
         if (!@socket_connect($this->resource, $address, $port)) {
46 46
             // ignore expected errors for non-blocking connections
47 47
             $errno = SocketError::getLast($this->resource);
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
      * @return array `[ 0 => address, 1 => port ]`
62 62
      * @throws SocketError
63 63
      */
64
-    public function getPeerName (): array {
64
+    public function getPeerName(): array {
65 65
         if ($this->getDomain() === AF_UNIX) {
66 66
             return [$this->getOption(17), 0]; // SO_PEERCRED is not exposed by PHP
67 67
         }
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
      * @return int Total bytes sent.
82 82
      * @throws SocketError
83 83
      */
84
-    public function send (string $data, int $flags = 0): int {
84
+    public function send(string $data, int $flags = 0): int {
85 85
         $count = @socket_send($this->resource, $data, strlen($data), $flags);
86 86
         if ($count === false) {
87 87
             throw new SocketError($this->resource); // reliable errno
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
      * @return $this
97 97
      * @throws SocketError `int` total bytes sent is set as the extra data.
98 98
      */
99
-    public function write (string $data) {
99
+    public function write(string $data) {
100 100
         $length = strlen($data);
101 101
         $total = 0;
102 102
         while ($total < $length) {
Please login to merge, or discard this patch.
src/SocketInterface.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -27,20 +27,20 @@
 block discarded – undo
27 27
      *
28 28
      * @return int
29 29
      */
30
-    public function getId (): int;
30
+    public function getId(): int;
31 31
 
32 32
     /**
33 33
      * Returns the underlying socket resource.
34 34
      *
35 35
      * @return resource
36 36
      */
37
-    public function getResource ();
37
+    public function getResource();
38 38
 
39 39
     /**
40 40
      * Whether the underlying resource is usable.
41 41
      *
42 42
      * @return bool
43 43
      */
44
-    public function isOpen (): bool;
44
+    public function isOpen(): bool;
45 45
 
46 46
 }
47 47
\ No newline at end of file
Please login to merge, or discard this patch.
src/SocketError.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
      * @param resource $resource PHP socket resource, or `null` for the global error.
30 30
      * @return int If the resource is closed or not a socket, `SOCKET_EBADF` is returned.
31 31
      */
32
-    public static function getLast ($resource = null) {
32
+    public static function getLast($resource = null) {
33 33
         if (isset($resource)) {
34 34
             if (@get_resource_type($resource) !== 'Socket') {
35 35
                 return SOCKET_EBADF; // Bad file descriptor
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
      * @param int $fallback Code to assume if one can't be found via the subject.
63 63
      * @param SocketError|null $previous Slippage of a prior error.
64 64
      */
65
-    public function __construct ($subject = null, $fallback = 0, SocketError $previous = null) {
65
+    public function __construct($subject = null, $fallback = 0, SocketError $previous = null) {
66 66
         if ($errno = is_int($subject) ? $subject : static::getLast($subject)) {
67 67
             $message = socket_strerror($errno);
68 68
         }
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
     /**
78 78
      * @return mixed
79 79
      */
80
-    public function getExtra () {
80
+    public function getExtra() {
81 81
         return $this->extra;
82 82
     }
83 83
 
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
      * @param mixed $extra
86 86
      * @return $this
87 87
      */
88
-    public function setExtra ($extra) {
88
+    public function setExtra($extra) {
89 89
         $this->extra = $extra;
90 90
         return $this;
91 91
     }
Please login to merge, or discard this patch.
src/WebSocket/FrameHandler.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -53,21 +53,21 @@  discard block
 block discarded – undo
53 53
      */
54 54
     protected $text = '';
55 55
 
56
-    public function __construct (WebSocketClient $client) {
56
+    public function __construct(WebSocketClient $client) {
57 57
         $this->client = $client;
58 58
     }
59 59
 
60 60
     /**
61 61
      * @return int
62 62
      */
63
-    public function getFragmentSize (): int {
63
+    public function getFragmentSize(): int {
64 64
         return $this->fragmentSize;
65 65
     }
66 66
 
67 67
     /**
68 68
      * @return int
69 69
      */
70
-    public function getMaxLength (): int {
70
+    public function getMaxLength(): int {
71 71
         return $this->maxLength;
72 72
     }
73 73
 
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
      * @param Frame $binary
80 80
      * @throws WebSocketError
81 81
      */
82
-    protected function onBinary (Frame $binary): void {
82
+    protected function onBinary(Frame $binary): void {
83 83
         $this->binary .= $binary->getPayload();
84 84
         if ($binary->isFinal()) {
85 85
             $message = $this->binary;
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
      *
100 100
      * @param Frame $close
101 101
      */
102
-    protected function onClose (Frame $close): void {
102
+    protected function onClose(Frame $close): void {
103 103
         $this->client->close($close->getCloseCode());
104 104
     }
105 105
 
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
      * @param Frame $frame
110 110
      * @throws WebSocketError
111 111
      */
112
-    protected function onContinue (Frame $frame): void {
112
+    protected function onContinue(Frame $frame): void {
113 113
         switch ($this->continue) {
114 114
             case Frame::OP_TEXT:
115 115
                 $this->onText($frame);
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
      *
136 136
      * @param Frame $control
137 137
      */
138
-    protected function onControl (Frame $control): void {
138
+    protected function onControl(Frame $control): void {
139 139
         if ($control->isClose()) {
140 140
             $this->onClose($control);
141 141
         }
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
      *
153 153
      * @param Frame $data
154 154
      */
155
-    protected function onData (Frame $data): void {
155
+    protected function onData(Frame $data): void {
156 156
         if (!$data->isFinal()) {
157 157
             $this->onData_SetContinue($data);
158 158
         }
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
         }
165 165
     }
166 166
 
167
-    protected function onData_SetContinue (Frame $data): void {
167
+    protected function onData_SetContinue(Frame $data): void {
168 168
         if ($this->continue) {
169 169
             $existing = Frame::NAMES[$this->continue];
170 170
             throw new WebSocketError(
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
      *
184 184
      * @param Frame $frame
185 185
      */
186
-    public function onFrame (Frame $frame): void {
186
+    public function onFrame(Frame $frame): void {
187 187
         $this->onFrame_CheckRsv($frame);
188 188
         $this->onFrame_CheckLength($frame);
189 189
         if ($frame->isControl()) {
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
     /**
201 201
      * @param Frame $frame
202 202
      */
203
-    protected function onFrame_CheckLength (Frame $frame): void {
203
+    protected function onFrame_CheckLength(Frame $frame): void {
204 204
         if ($frame->isData()) {
205 205
             if ($frame->isBinary()) {
206 206
                 $length = strlen($this->binary);
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
      * @param Frame $frame
225 225
      * @throws WebSocketError
226 226
      */
227
-    protected function onFrame_CheckRsv (Frame $frame): void {
227
+    protected function onFrame_CheckRsv(Frame $frame): void {
228 228
         if ($badRsv = $frame->getRsv() & ~$this->client->getHandshake()->getRsv()) {
229 229
             $badRsv = str_pad(base_convert($badRsv >> 4, 10, 2), 3, '0', STR_PAD_LEFT);
230 230
             throw new WebSocketError(Frame::CLOSE_PROTOCOL_ERROR, "Received unknown RSV bits: 0b{$badRsv}");
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
      *
239 239
      * @param Frame $ping
240 240
      */
241
-    protected function onPing (Frame $ping): void {
241
+    protected function onPing(Frame $ping): void {
242 242
         $this->writePong($ping->getPayload());
243 243
     }
244 244
 
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
      *
250 250
      * @param Frame $pong
251 251
      */
252
-    protected function onPong (Frame $pong): void {
252
+    protected function onPong(Frame $pong): void {
253 253
         // stub
254 254
     }
255 255
 
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
      * @param Frame $text
262 262
      * @throws WebSocketError
263 263
      */
264
-    protected function onText (Frame $text): void {
264
+    protected function onText(Frame $text): void {
265 265
         $this->text .= $text->getPayload();
266 266
         if ($text->isFinal()) {
267 267
             $message = $this->text;
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
      * @param int $bytes
275 275
      * @return $this
276 276
      */
277
-    public function setFragmentSize (int $bytes) {
277
+    public function setFragmentSize(int $bytes) {
278 278
         $this->fragmentSize = $bytes;
279 279
         return $this;
280 280
     }
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
      * @param int $bytes
284 284
      * @return $this
285 285
      */
286
-    public function setMaxLength (int $bytes) {
286
+    public function setMaxLength(int $bytes) {
287 287
         $this->maxLength = $bytes;
288 288
         return $this;
289 289
     }
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
      * @param int $opCode
295 295
      * @param string $payload
296 296
      */
297
-    public function write (int $opCode, string $payload): void {
297
+    public function write(int $opCode, string $payload): void {
298 298
         $offset = 0;
299 299
         $total = strlen($payload);
300 300
         do {
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
     /**
311 311
      * @param string $payload
312 312
      */
313
-    public function writeBinary (string $payload): void {
313
+    public function writeBinary(string $payload): void {
314 314
         $this->write(Frame::OP_BINARY, $payload);
315 315
     }
316 316
 
@@ -318,8 +318,8 @@  discard block
 block discarded – undo
318 318
      * @param int $code
319 319
      * @param string $reason
320 320
      */
321
-    public function writeClose (int $code = Frame::CLOSE_NORMAL, string $reason = ''): void {
322
-        $this->writeFrame(true, Frame::OP_CLOSE, pack('n', $code) . $reason);
321
+    public function writeClose(int $code = Frame::CLOSE_NORMAL, string $reason = ''): void {
322
+        $this->writeFrame(true, Frame::OP_CLOSE, pack('n', $code).$reason);
323 323
     }
324 324
 
325 325
     /**
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
      * @param int $opCode
330 330
      * @param string $payload
331 331
      */
332
-    protected function writeFrame (bool $final, int $opCode, string $payload): void {
332
+    protected function writeFrame(bool $final, int $opCode, string $payload): void {
333 333
         if ($opCode & 0x08 and !$final) {
334 334
             throw new WebSocketError(
335 335
                 Frame::CLOSE_INTERNAL_ERROR,
@@ -349,27 +349,27 @@  discard block
 block discarded – undo
349 349
         else {
350 350
             $head .= chr($length);
351 351
         }
352
-        $this->client->write($head . $payload);
352
+        $this->client->write($head.$payload);
353 353
     }
354 354
 
355 355
     /**
356 356
      * @param string $payload
357 357
      */
358
-    public function writePing (string $payload = ''): void {
358
+    public function writePing(string $payload = ''): void {
359 359
         $this->writeFrame(true, Frame::OP_PING, $payload);
360 360
     }
361 361
 
362 362
     /**
363 363
      * @param string $payload
364 364
      */
365
-    public function writePong (string $payload = ''): void {
365
+    public function writePong(string $payload = ''): void {
366 366
         $this->writeFrame(true, Frame::OP_PONG, $payload);
367 367
     }
368 368
 
369 369
     /**
370 370
      * @param string $payload
371 371
      */
372
-    public function writeText (string $payload): void {
372
+    public function writeText(string $payload): void {
373 373
         $this->write(Frame::OP_TEXT, $payload);
374 374
     }
375 375
 }
376 376
\ No newline at end of file
Please login to merge, or discard this patch.
src/WebSocket/WebSocketServer.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
      * @param $resource
30 30
      * @param Reactor $reactor
31 31
      */
32
-    public function __construct ($resource, Reactor $reactor) {
32
+    public function __construct($resource, Reactor $reactor) {
33 33
         parent::__construct($resource);
34 34
         $reactor->add($this);
35 35
         $this->reactor = $reactor;
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
     /**
39 39
      * @return WebSocketClient
40 40
      */
41
-    public function accept () {
41
+    public function accept() {
42 42
         /** @var WebSocketClient $client */
43 43
         $client = parent::accept();
44 44
         $this->clients[$client->getId()] = $client;
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
      * @param int $opCode
53 53
      * @param string $payload
54 54
      */
55
-    public function broadcast (int $opCode, string $payload) {
55
+    public function broadcast(int $opCode, string $payload) {
56 56
         foreach ($this->clients as $client) {
57 57
             if ($client->isOk()) {
58 58
                 $client->getFrameHandler()->write($opCode, $payload);
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
     /**
64 64
      * @param string $payload
65 65
      */
66
-    public function broadcastBinary (string $payload) {
66
+    public function broadcastBinary(string $payload) {
67 67
         $this->broadcast(Frame::OP_BINARY, $payload);
68 68
     }
69 69
 
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
      *
73 73
      * @param string $payload
74 74
      */
75
-    public function broadcastPing (string $payload = '') {
75
+    public function broadcastPing(string $payload = '') {
76 76
         $this->broadcast(Frame::OP_PING, $payload);
77 77
     }
78 78
 
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
      *
82 82
      * @param string $text
83 83
      */
84
-    public function broadcastText (string $text) {
84
+    public function broadcastText(string $text) {
85 85
         $this->broadcast(Frame::OP_TEXT, $text);
86 86
     }
87 87
 
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
      * @param string $reason
93 93
      * @return StreamServer
94 94
      */
95
-    public function close (int $code = Frame::CLOSE_INTERRUPT, $reason = '') {
95
+    public function close(int $code = Frame::CLOSE_INTERRUPT, $reason = '') {
96 96
         foreach ($this->clients as $client) {
97 97
             try {
98 98
                 $client->close($code, $reason);
@@ -110,14 +110,14 @@  discard block
 block discarded – undo
110 110
      *
111 111
      * @return int
112 112
      */
113
-    public function count (): int {
113
+    public function count(): int {
114 114
         return count($this->clients);
115 115
     }
116 116
 
117 117
     /**
118 118
      * @return WebSocketClient[]
119 119
      */
120
-    public function getClients () {
120
+    public function getClients() {
121 121
         return $this->clients;
122 122
     }
123 123
 
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
      * @param resource $resource
126 126
      * @return WebSocketClient
127 127
      */
128
-    protected function newClient ($resource) {
128
+    protected function newClient($resource) {
129 129
         return new WebSocketClient($resource, $this);
130 130
     }
131 131
 
@@ -134,13 +134,13 @@  discard block
 block discarded – undo
134 134
      *
135 135
      * @inheritDoc
136 136
      */
137
-    final public function onOutOfBand (): void {
137
+    final public function onOutOfBand(): void {
138 138
     }
139 139
 
140 140
     /**
141 141
      * @inheritDoc
142 142
      */
143
-    public function onReadable (): void {
143
+    public function onReadable(): void {
144 144
         $this->accept();
145 145
     }
146 146
 
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
      *
150 150
      * @param WebSocketClient $client
151 151
      */
152
-    public function remove (WebSocketClient $client) {
152
+    public function remove(WebSocketClient $client) {
153 153
         unset($this->clients[$client->getId()]);
154 154
         $this->reactor->remove($client);
155 155
     }
Please login to merge, or discard this patch.