Completed
Push — master ( f836de...b537f9 )
by y
01:15
created
src/WebSocket/HandShake.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -48,28 +48,28 @@  discard block
 block discarded – undo
48 48
     /**
49 49
      * @param WebSocketClient $client
50 50
      */
51
-    public function __construct (WebSocketClient $client) {
51
+    public function __construct(WebSocketClient $client) {
52 52
         $this->client = $client;
53 53
     }
54 54
 
55 55
     /**
56 56
      * @return string[]
57 57
      */
58
-    public function getHeaders () {
58
+    public function getHeaders() {
59 59
         return $this->headers;
60 60
     }
61 61
 
62 62
     /**
63 63
      * @return string
64 64
      */
65
-    public function getMethod (): string {
65
+    public function getMethod(): string {
66 66
         return $this->method;
67 67
     }
68 68
 
69 69
     /**
70 70
      * @return int
71 71
      */
72
-    public function getRsv (): int {
72
+    public function getRsv(): int {
73 73
         return $this->rsv;
74 74
     }
75 75
 
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
      * @return bool
80 80
      * @throws WebSocketError
81 81
      */
82
-    public function negotiate (): bool {
82
+    public function negotiate(): bool {
83 83
         $this->buffer .= $this->client->recvAll();
84 84
         try {
85 85
             if (strlen($this->buffer) > $this->sizeLimit) {
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
                 $key = strtolower(trim($key));
100 100
                 $value = trim($value);
101 101
                 if (isset($this->headers[$key])) {
102
-                    $this->headers[$key] .= ', ' . $value;
102
+                    $this->headers[$key] .= ', '.$value;
103 103
                 }
104 104
                 else {
105 105
                     $this->headers[$key] = $value;
@@ -120,12 +120,12 @@  discard block
 block discarded – undo
120 120
     /**
121 121
      * Sends the connection upgrade headers.
122 122
      */
123
-    protected function upgrade (): void {
123
+    protected function upgrade(): void {
124 124
         $this->client->write(implode("\r\n", [
125 125
             "HTTP/1.1 101 Switching Protocols",
126 126
             "Connection: Upgrade",
127 127
             "Upgrade: websocket",
128
-            "Sec-WebSocket-Accept: " . base64_encode(sha1($this->headers['sec-websocket-key'] . self::RFC_GUID, true)),
128
+            "Sec-WebSocket-Accept: ".base64_encode(sha1($this->headers['sec-websocket-key'].self::RFC_GUID, true)),
129 129
         ]));
130 130
     }
131 131
 
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
      *
135 135
      * @throws WebSocketError
136 136
      */
137
-    protected function validate (): void {
137
+    protected function validate(): void {
138 138
         if (!(
139 139
             $check = 'method = http 1.1'
140 140
             and preg_match('/HTTP\/1\.1$/i', $this->method)
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
@@ -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);
@@ -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.
src/WebSocket/WebSocketClient.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
      * @param resource $resource
52 52
      * @param WebSocketServer $server
53 53
      */
54
-    public function __construct ($resource, WebSocketServer $server) {
54
+    public function __construct($resource, WebSocketServer $server) {
55 55
         parent::__construct($resource);
56 56
         $this->server = $server;
57 57
     }
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
      * @param string $reason
75 75
      * @return $this
76 76
      */
77
-    public function close (int $code = null, string $reason = '') {
77
+    public function close(int $code = null, string $reason = '') {
78 78
         try {
79 79
             if ($code >= 1000 and $this->state === self::STATE_OK) {
80 80
                 $this->getFrameHandler()->writeClose($code, $reason);
@@ -91,49 +91,49 @@  discard block
 block discarded – undo
91 91
     /**
92 92
      * @return FrameHandler
93 93
      */
94
-    public function getFrameHandler (): FrameHandler {
94
+    public function getFrameHandler(): FrameHandler {
95 95
         return $this->frameHandler ?? $this->frameHandler = new FrameHandler($this);
96 96
     }
97 97
 
98 98
     /**
99 99
      * @return FrameReader
100 100
      */
101
-    public function getFrameReader (): FrameReader {
101
+    public function getFrameReader(): FrameReader {
102 102
         return $this->frameReader ?? $this->frameReader = new FrameReader($this);
103 103
     }
104 104
 
105 105
     /**
106 106
      * @return HandShake
107 107
      */
108
-    public function getHandshake (): HandShake {
108
+    public function getHandshake(): HandShake {
109 109
         return $this->handshake ?? $this->handshake = new HandShake($this);
110 110
     }
111 111
 
112 112
     /**
113 113
      * @return MessageHandler
114 114
      */
115
-    public function getMessageHandler (): MessageHandler {
115
+    public function getMessageHandler(): MessageHandler {
116 116
         return $this->messageHandler ?? $this->messageHandler = new MessageHandler($this);
117 117
     }
118 118
 
119 119
     /**
120 120
      * @return WebSocketServer
121 121
      */
122
-    public function getServer (): WebSocketServer {
122
+    public function getServer(): WebSocketServer {
123 123
         return $this->server;
124 124
     }
125 125
 
126 126
     /**
127 127
      * @return int
128 128
      */
129
-    public function getState (): int {
129
+    public function getState(): int {
130 130
         return $this->state;
131 131
     }
132 132
 
133 133
     /**
134 134
      * @return bool
135 135
      */
136
-    final public function isOk (): bool {
136
+    final public function isOk(): bool {
137 137
         return $this->state === self::STATE_OK;
138 138
     }
139 139
 
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
      *
143 143
      * The RFC says the connection must be dropped if any unsupported activity occurs.
144 144
      */
145
-    final public function onOutOfBand (): void {
145
+    final public function onOutOfBand(): void {
146 146
         $this->close(Frame::CLOSE_PROTOCOL_ERROR, "Received out-of-band data.");
147 147
     }
148 148
 
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
      *
152 152
      * @throws Exception
153 153
      */
154
-    public function onReadable (): void {
154
+    public function onReadable(): void {
155 155
         if (!strlen($this->recv(1, MSG_PEEK))) { // peer has shut down writing, or closed.
156 156
             $this->close();
157 157
             return;
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
     /**
188 188
      * Called when the initial connection handshake succeeds and frame I/O can occur.
189 189
      */
190
-    protected function onStateOk (): void {
190
+    protected function onStateOk(): void {
191 191
         // stub
192 192
     }
193 193
 
Please login to merge, or discard this patch.
src/WebSocket/FrameReader.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
      */
50 50
     protected $maxLength = 10 * 1024 * 1024;
51 51
 
52
-    public function __construct (WebSocketClient $client) {
52
+    public function __construct(WebSocketClient $client) {
53 53
         $this->client = $client;
54 54
     }
55 55
 
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
      * @return null|Frame
58 58
      * @throws WebSocketError
59 59
      */
60
-    protected function getFrame (): ?Frame {
60
+    protected function getFrame(): ?Frame {
61 61
         if (!$this->head) {
62 62
             if (preg_match(self::REGEXP, $this->buffer, $head)) {
63 63
                 [, $op, $len] = unpack('C2', $head[0]);
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
      *
100 100
      * @return Generator|Frame[]
101 101
      */
102
-    public function getFrames () {
102
+    public function getFrames() {
103 103
         $this->buffer .= $this->client->recvAll();
104 104
         while ($frame = $this->getFrame()) {
105 105
             yield $frame;
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
     /**
110 110
      * @return int
111 111
      */
112
-    public function getMaxLength (): int {
112
+    public function getMaxLength(): int {
113 113
         return $this->maxLength;
114 114
     }
115 115
 
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
      * @param int $bytes
118 118
      * @return $this
119 119
      */
120
-    public function setMaxLength (int $bytes) {
120
+    public function setMaxLength(int $bytes) {
121 121
         if ($bytes < self::MAX_LENGTH_RANGE[0] or $bytes > self::MAX_LENGTH_RANGE[1]) {
122 122
             throw new InvalidArgumentException('Max length must be within range [125,2^63-1]');
123 123
         }
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
      *
131 131
      * @throws WebSocketError
132 132
      */
133
-    protected function validate (): void {
133
+    protected function validate(): void {
134 134
         if ($this->head['length'] > $this->maxLength) {
135 135
             throw new WebSocketError(Frame::CLOSE_TOO_LARGE, "Payload would exceed {$this->maxLength} bytes");
136 136
         }
Please login to merge, or discard this patch.
src/WebSocket/MessageHandler.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
     /**
16 16
      * @param WebSocketClient $client
17 17
      */
18
-    public function __construct (WebSocketClient $client) {
18
+    public function __construct(WebSocketClient $client) {
19 19
         $this->client = $client;
20 20
     }
21 21
 
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
      *
25 25
      * @param string $binary
26 26
      */
27
-    public function onBinary (string $binary): void {
27
+    public function onBinary(string $binary): void {
28 28
         unset($binary);
29 29
         throw new WebSocketError(Frame::CLOSE_UNHANDLED_DATA, "I don't handle binary data.");
30 30
     }
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
      *
35 35
      * @param string $text
36 36
      */
37
-    public function onText (string $text): void {
37
+    public function onText(string $text): void {
38 38
         $this->onText_CheckUtf8($text);
39 39
         throw new WebSocketError(Frame::CLOSE_UNHANDLED_DATA, "I don't handle text.");
40 40
     }
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
      *
45 45
      * @param string $text
46 46
      */
47
-    protected function onText_CheckUtf8 (string $text): void {
47
+    protected function onText_CheckUtf8(string $text): void {
48 48
         if (!mb_detect_encoding($text, 'UTF-8', true)) {
49 49
             throw new WebSocketError(Frame::CLOSE_BAD_DATA, "Received TEXT is not UTF-8.");
50 50
         }
Please login to merge, or discard this patch.
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
 
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
      *
128 128
      * @return $this
129 129
      */
130
-    public function close () {
130
+    public function close() {
131 131
         socket_close($this->resource); // never errors
132 132
         return $this;
133 133
     }
@@ -137,15 +137,15 @@  discard block
 block discarded – undo
137 137
      *
138 138
      * @return int
139 139
      */
140
-    final public function getDomain (): int {
140
+    final public function getDomain(): int {
141 141
         return $this->getOption(39); // SO_DOMAIN is not exposed by PHP
142 142
     }
143 143
 
144 144
     /**
145 145
      * @return int
146 146
      */
147
-    final public function getId (): int {
148
-        return (int)$this->resource;
147
+    final public function getId(): int {
148
+        return (int) $this->resource;
149 149
     }
150 150
 
151 151
     /**
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
      * @return mixed The option's value. This is never `false`.
158 158
      * @throws SocketError
159 159
      */
160
-    public function getOption (int $option) {
160
+    public function getOption(int $option) {
161 161
         $value = @socket_get_option($this->resource, SOL_SOCKET, $option);
162 162
         if ($value === false) {
163 163
             throw new SocketError($this->resource, SOCKET_EINVAL);
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
     /**
169 169
      * @return resource
170 170
      */
171
-    final public function getResource () {
171
+    final public function getResource() {
172 172
         return $this->resource;
173 173
     }
174 174
 
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
      * @return array `[ 0 => address, 1 => port ]`
181 181
      * @throws SocketError
182 182
      */
183
-    public function getSockName (): array {
183
+    public function getSockName(): array {
184 184
         if (!@socket_getsockname($this->resource, $addr, $port)) {
185 185
             throw new SocketError($this->resource, SOCKET_EOPNOTSUPP);
186 186
         }
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
     /**
191 191
      * @return bool
192 192
      */
193
-    public function isOpen (): bool {
193
+    public function isOpen(): bool {
194 194
         return is_resource($this->resource);
195 195
     }
196 196
 
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
      *
202 202
      * @return bool
203 203
      */
204
-    final public function isOutOfBand (): bool {
204
+    final public function isOutOfBand(): bool {
205 205
         return $this->isReady(self::CH_EXCEPT);
206 206
     }
207 207
 
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
      *
213 213
      * @return bool
214 214
      */
215
-    final public function isReadable (): bool {
215
+    final public function isReadable(): bool {
216 216
         return $this->isReady(self::CH_READ);
217 217
     }
218 218
 
@@ -226,15 +226,15 @@  discard block
 block discarded – undo
226 226
      * @return bool
227 227
      * @throws SocketError
228 228
      */
229
-    public function isReady (int $channel, ?float $timeout = 0): bool {
229
+    public function isReady(int $channel, ?float $timeout = 0): bool {
230 230
         $rwe = [$channel => [$this->resource]];
231 231
         // core casts non-null timeout to int.
232 232
         // usec is ignored if timeout is null.
233
-        $usec = (int)(fmod($timeout, 1) * 1000000);
233
+        $usec = (int) (fmod($timeout, 1) * 1000000);
234 234
         if (false === $count = @socket_select($rwe[0], $rwe[1], $rwe[2], $timeout, $usec)) {
235 235
             throw new SocketError($this->resource);
236 236
         }
237
-        return (bool)$count;
237
+        return (bool) $count;
238 238
     }
239 239
 
240 240
     /**
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
      *
245 245
      * @return bool
246 246
      */
247
-    final public function isWritable (): bool {
247
+    final public function isWritable(): bool {
248 248
         return $this->isReady(self::CH_WRITE);
249 249
     }
250 250
 
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
      * @return $this
269 269
      * @throws SocketError
270 270
      */
271
-    public function setBlocking (bool $blocking) {
271
+    public function setBlocking(bool $blocking) {
272 272
         if ($blocking ? @socket_set_block($this->resource) : @socket_set_nonblock($this->resource)) {
273 273
             return $this;
274 274
         }
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
      * @return $this
286 286
      * @throws SocketError
287 287
      */
288
-    public function setOption (int $option, $value) {
288
+    public function setOption(int $option, $value) {
289 289
         if (!@socket_set_option($this->resource, SOL_SOCKET, $option, $value)) {
290 290
             throw new SocketError($this->resource, SOCKET_EINVAL);
291 291
         }
@@ -298,10 +298,10 @@  discard block
 block discarded – undo
298 298
      * @param float $timeout Zero means "no timeout" (block forever).
299 299
      * @return $this
300 300
      */
301
-    public function setTimeout (float $timeout) {
301
+    public function setTimeout(float $timeout) {
302 302
         $tv = [
303
-            'sec' => (int)$timeout,
304
-            'usec' => (int)(fmod($timeout, 1) * 1000000)
303
+            'sec' => (int) $timeout,
304
+            'usec' => (int) (fmod($timeout, 1) * 1000000)
305 305
         ];
306 306
         $this->setOption(SO_RCVTIMEO, $tv);
307 307
         $this->setOption(SO_SNDTIMEO, $tv);
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
      * @return $this
332 332
      * @throws SocketError
333 333
      */
334
-    public function shutdown (int $channel) {
334
+    public function shutdown(int $channel) {
335 335
         if (!@socket_shutdown($this->resource, $channel)) {
336 336
             throw new SocketError($this->resource); // reliable errno
337 337
         }
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
      * @return StreamClient
26 26
      * @throws SocketError
27 27
      */
28
-    public function accept (): StreamClient {
28
+    public function accept(): StreamClient {
29 29
         if (!$resource = @socket_accept($this->resource)) {
30 30
             throw new SocketError($this->resource); // reliable errno
31 31
         }
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
      * @return $this
46 46
      * @throws SocketError
47 47
      */
48
-    public function listen (int $backlog = 0) {
48
+    public function listen(int $backlog = 0) {
49 49
         if (!@socket_listen($this->resource, $backlog)) {
50 50
             throw new SocketError($this->resource); // reliable errno
51 51
         }
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
      * @param resource $resource The accepted connection.
59 59
      * @return StreamClient
60 60
      */
61
-    protected function newClient ($resource): StreamClient {
61
+    protected function newClient($resource): StreamClient {
62 62
         return new StreamClient($resource);
63 63
     }
64 64
 
Please login to merge, or discard this patch.
src/WebSocket/FrameHandler.php 1 patch
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
 
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
      * @param Frame $binary
76 76
      * @throws WebSocketError
77 77
      */
78
-    protected function onBinary (Frame $binary): void {
78
+    protected function onBinary(Frame $binary): void {
79 79
         $this->buffer .= $binary->getPayload();
80 80
         if ($binary->isFinal()) {
81 81
             $message = $this->buffer;
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
      *
96 96
      * @param Frame $close
97 97
      */
98
-    protected function onClose (Frame $close): void {
98
+    protected function onClose(Frame $close): void {
99 99
         $this->client->close($close->getCloseCode());
100 100
     }
101 101
 
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
      * @param Frame $fragment
106 106
      * @throws WebSocketError
107 107
      */
108
-    protected function onContinue (Frame $fragment): void {
108
+    protected function onContinue(Frame $fragment): void {
109 109
         if (!$this->continue) {
110 110
             throw new WebSocketError(
111 111
                 Frame::CLOSE_PROTOCOL_ERROR,
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
      *
138 138
      * @param Frame $control
139 139
      */
140
-    protected function onControl (Frame $control): void {
140
+    protected function onControl(Frame $control): void {
141 141
         if ($control->isClose()) {
142 142
             $this->onClose($control);
143 143
         }
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
      *
155 155
      * @param Frame $data
156 156
      */
157
-    protected function onData (Frame $data): void {
157
+    protected function onData(Frame $data): void {
158 158
         $this->onData_SetContinue($data);
159 159
         if ($data->isText()) {
160 160
             $this->onText($data);
@@ -168,11 +168,11 @@  discard block
 block discarded – undo
168 168
      * @param Frame $data
169 169
      * @throws WebSocketError
170 170
      */
171
-    protected function onData_SetContinue (Frame $data): void {
171
+    protected function onData_SetContinue(Frame $data): void {
172 172
         if ($this->continue) {
173 173
             throw new WebSocketError(
174 174
                 Frame::CLOSE_PROTOCOL_ERROR,
175
-                "Received interleaved {$data->getName()} against existing " . Frame::NAMES[$this->continue],
175
+                "Received interleaved {$data->getName()} against existing ".Frame::NAMES[$this->continue],
176 176
                 $data
177 177
             );
178 178
         }
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
      *
189 189
      * @param Frame $frame
190 190
      */
191
-    public function onFrame (Frame $frame): void {
191
+    public function onFrame(Frame $frame): void {
192 192
         $this->onFrame_CheckRsv($frame);
193 193
         $this->onFrame_CheckLength($frame);
194 194
         if ($frame->isControl()) {
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
      * @param Frame $frame
207 207
      * @throws WebSocketError
208 208
      */
209
-    protected function onFrame_CheckLength (Frame $frame): void {
209
+    protected function onFrame_CheckLength(Frame $frame): void {
210 210
         if ($frame->isData()) {
211 211
             $length = strlen($this->buffer);
212 212
             if ($length + $frame->getLength() > $this->maxLength) {
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
      * @param Frame $frame
226 226
      * @throws WebSocketError
227 227
      */
228
-    protected function onFrame_CheckRsv (Frame $frame): void {
228
+    protected function onFrame_CheckRsv(Frame $frame): void {
229 229
         if ($badRsv = $frame->getRsv() & ~$this->client->getHandshake()->getRsv()) {
230 230
             $badRsv = str_pad(base_convert($badRsv >> 4, 10, 2), 3, '0', STR_PAD_LEFT);
231 231
             throw new WebSocketError(
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
      *
244 244
      * @param Frame $ping
245 245
      */
246
-    protected function onPing (Frame $ping): void {
246
+    protected function onPing(Frame $ping): void {
247 247
         $this->writePong($ping->getPayload());
248 248
     }
249 249
 
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
      *
255 255
      * @param Frame $pong
256 256
      */
257
-    protected function onPong (Frame $pong): void {
257
+    protected function onPong(Frame $pong): void {
258 258
         // stub
259 259
     }
260 260
 
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
      * @param Frame $text
265 265
      * @throws WebSocketError
266 266
      */
267
-    protected function onText (Frame $text): void {
267
+    protected function onText(Frame $text): void {
268 268
         $this->buffer .= $text->getPayload();
269 269
         if ($text->isFinal()) {
270 270
             $message = $this->buffer;
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
      * @param int $bytes
278 278
      * @return $this
279 279
      */
280
-    public function setFragmentSize (int $bytes) {
280
+    public function setFragmentSize(int $bytes) {
281 281
         $this->fragmentSize = $bytes;
282 282
         return $this;
283 283
     }
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
      * @param int $bytes
287 287
      * @return $this
288 288
      */
289
-    public function setMaxLength (int $bytes) {
289
+    public function setMaxLength(int $bytes) {
290 290
         $this->maxLength = $bytes;
291 291
         return $this;
292 292
     }
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
      * @param int $opCode
298 298
      * @param string $payload
299 299
      */
300
-    public function write (int $opCode, string $payload): void {
300
+    public function write(int $opCode, string $payload): void {
301 301
         $offset = 0;
302 302
         $total = strlen($payload);
303 303
         do {
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
     /**
314 314
      * @param string $payload
315 315
      */
316
-    public function writeBinary (string $payload): void {
316
+    public function writeBinary(string $payload): void {
317 317
         $this->write(Frame::OP_BINARY, $payload);
318 318
     }
319 319
 
@@ -321,8 +321,8 @@  discard block
 block discarded – undo
321 321
      * @param int $code
322 322
      * @param string $reason
323 323
      */
324
-    public function writeClose (int $code = Frame::CLOSE_NORMAL, string $reason = ''): void {
325
-        $this->writeFrame(true, Frame::OP_CLOSE, pack('n', $code) . $reason);
324
+    public function writeClose(int $code = Frame::CLOSE_NORMAL, string $reason = ''): void {
325
+        $this->writeFrame(true, Frame::OP_CLOSE, pack('n', $code).$reason);
326 326
     }
327 327
 
328 328
     /**
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
      * @param int $opCode
333 333
      * @param string $payload
334 334
      */
335
-    protected function writeFrame (bool $final, int $opCode, string $payload): void {
335
+    protected function writeFrame(bool $final, int $opCode, string $payload): void {
336 336
         if ($opCode & 0x08 and !$final) {
337 337
             throw new LogicException("Would have sent a fragmented control frame ({$opCode}) {$payload}");
338 338
         }
@@ -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/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) {
83
+    public function onError(int $channel, $socket, Throwable $error) {
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.