Completed
Push — master ( f4f26a...b354c6 )
by y
01:22
created
src/AbstractSocket.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
      * @see https://php.net/socket_get_option
152 152
      *
153 153
      * @param int $option `SO_*` option constant.
154
-     * @return mixed The option's value. This is never `false`.
154
+     * @return integer The option's value. This is never `false`.
155 155
      * @throws SocketError
156 156
      */
157 157
     public function getOption (int $option) {
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
      * @see await()
214 214
      *
215 215
      * @param int $channel `SocketInterface` channel constant.
216
-     * @param float|null $timeout Maximum seconds to block. `NULL` blocks forever. Defaults to a poll.
216
+     * @param integer $timeout Maximum seconds to block. `NULL` blocks forever. Defaults to a poll.
217 217
      * @return bool
218 218
      * @throws SocketError
219 219
      */
Please login to merge, or discard this 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,12 +137,12 @@  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
-    final public function getId (): int {
145
-        return (int)$this->resource;
144
+    final public function getId(): int {
145
+        return (int) $this->resource;
146 146
     }
147 147
 
148 148
     /**
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
      * @return mixed The option's value. This is never `false`.
155 155
      * @throws SocketError
156 156
      */
157
-    public function getOption (int $option) {
157
+    public function getOption(int $option) {
158 158
         $value = @socket_get_option($this->resource, SOL_SOCKET, $option);
159 159
         if ($value === false) {
160 160
             throw new SocketError($this->resource, SOCKET_EINVAL);
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
         return $value;
163 163
     }
164 164
 
165
-    final public function getResource () {
165
+    final public function getResource() {
166 166
         return $this->resource;
167 167
     }
168 168
 
@@ -174,14 +174,14 @@  discard block
 block discarded – undo
174 174
      * @return array `[ 0 => address, 1 => port ]`
175 175
      * @throws SocketError
176 176
      */
177
-    public function getSockName (): array {
177
+    public function getSockName(): array {
178 178
         if (!@socket_getsockname($this->resource, $addr, $port)) {
179 179
             throw new SocketError($this->resource, SOCKET_EOPNOTSUPP);
180 180
         }
181 181
         return [$addr, $port];
182 182
     }
183 183
 
184
-    public function isOpen (): bool {
184
+    public function isOpen(): bool {
185 185
         return is_resource($this->resource);
186 186
     }
187 187
 
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
      *
193 193
      * @return bool
194 194
      */
195
-    final public function isOutOfBand (): bool {
195
+    final public function isOutOfBand(): bool {
196 196
         return $this->isReady(self::CH_EXCEPT);
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 isReadable (): bool {
206
+    final public function isReadable(): bool {
207 207
         return $this->isReady(self::CH_READ);
208 208
     }
209 209
 
@@ -217,15 +217,15 @@  discard block
 block discarded – undo
217 217
      * @return bool
218 218
      * @throws SocketError
219 219
      */
220
-    public function isReady (int $channel, ?float $timeout = 0): bool {
220
+    public function isReady(int $channel, ?float $timeout = 0): bool {
221 221
         $rwe = [$channel => [$this->resource]];
222 222
         // core casts non-null timeout to int.
223 223
         // usec is ignored if timeout is null.
224
-        $usec = (int)(fmod($timeout, 1) * 1000000);
224
+        $usec = (int) (fmod($timeout, 1) * 1000000);
225 225
         if (false === $count = @socket_select($rwe[0], $rwe[1], $rwe[2], $timeout, $usec)) {
226 226
             throw new SocketError($this->resource);
227 227
         }
228
-        return (bool)$count;
228
+        return (bool) $count;
229 229
     }
230 230
 
231 231
     /**
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
      *
236 236
      * @return bool
237 237
      */
238
-    final public function isWritable (): bool {
238
+    final public function isWritable(): bool {
239 239
         return $this->isReady(self::CH_WRITE);
240 240
     }
241 241
 
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
      * @return $this
258 258
      * @throws SocketError
259 259
      */
260
-    public function setBlocking (bool $blocking) {
260
+    public function setBlocking(bool $blocking) {
261 261
         if ($blocking ? @socket_set_block($this->resource) : @socket_set_nonblock($this->resource)) {
262 262
             return $this;
263 263
         }
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
      * @return $this
275 275
      * @throws SocketError
276 276
      */
277
-    public function setOption (int $option, $value) {
277
+    public function setOption(int $option, $value) {
278 278
         if (!@socket_set_option($this->resource, SOL_SOCKET, $option, $value)) {
279 279
             throw new SocketError($this->resource, SOCKET_EINVAL);
280 280
         }
@@ -287,10 +287,10 @@  discard block
 block discarded – undo
287 287
      * @param float $timeout Zero means "no timeout" (block forever).
288 288
      * @return $this
289 289
      */
290
-    public function setTimeout (float $timeout) {
290
+    public function setTimeout(float $timeout) {
291 291
         $tv = [
292
-            'sec' => (int)$timeout,
293
-            'usec' => (int)(fmod($timeout, 1) * 1000000)
292
+            'sec' => (int) $timeout,
293
+            'usec' => (int) (fmod($timeout, 1) * 1000000)
294 294
         ];
295 295
         $this->setOption(SO_RCVTIMEO, $tv);
296 296
         $this->setOption(SO_SNDTIMEO, $tv);
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
      * @return $this
321 321
      * @throws SocketError
322 322
      */
323
-    public function shutdown (int $channel) {
323
+    public function shutdown(int $channel) {
324 324
         if (!@socket_shutdown($this->resource, $channel)) {
325 325
             throw new SocketError($this->resource); // reliable errno
326 326
         }
Please login to merge, or discard this patch.
src/StreamClient.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@
 block discarded – undo
22 22
      * @see https://php.net/socket_create_pair
23 23
      *
24 24
      * @param array $extra Variadic constructor arguments.
25
-     * @return static[] Two instances at indices `0` and `1`.
25
+     * @return StreamClient[] Two instances at indices `0` and `1`.
26 26
      * @throws SocketError
27 27
      */
28 28
     public static function newUnixPair (...$extra) {
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 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 static[] Two instances at indices `0` and `1`.
26 26
      * @throws SocketError
27 27
      */
28
-    public static function newUnixPair (...$extra) {
28
+    public static function newUnixPair(...$extra) {
29 29
         if (!@socket_create_pair(AF_UNIX, SOCK_STREAM, 0, $fd)) {
30 30
             throw new SocketError; // reliable errno
31 31
         }
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
      * @return string
45 45
      * @throws SocketError The partially read data is attached.
46 46
      */
47
-    public function read (int $length): string {
47
+    public function read(int $length): string {
48 48
         try {
49 49
             $data = '';
50 50
             do {
@@ -71,11 +71,11 @@  discard block
 block discarded – undo
71 71
      * @return string
72 72
      * @throws SocketError
73 73
      */
74
-    public function recv (int $maxLength, int $flags = 0): string {
74
+    public function recv(int $maxLength, int $flags = 0): string {
75 75
         if (false === @socket_recv($this->resource, $data, $maxLength, $flags)) {
76 76
             throw new SocketError($this->resource, SOCKET_EINVAL);
77 77
         }
78
-        return (string)$data; // cast needed, will be null if 0 bytes are read.
78
+        return (string) $data; // cast needed, will be null if 0 bytes are read.
79 79
     }
80 80
 
81 81
     /**
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
      * @return string
86 86
      * @throws SocketError
87 87
      */
88
-    public function recvAll (int $flags = 0): string {
88
+    public function recvAll(int $flags = 0): string {
89 89
         $flags = ($flags & ~MSG_WAITALL) | MSG_DONTWAIT;
90 90
         $length = $this->getOption(SO_RCVBUF);
91 91
         try {
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -52,8 +52,7 @@  discard block
 block discarded – undo
52 52
                 $length -= $chunkSize = strlen($chunk);
53 53
             } while ($chunkSize and $length);
54 54
             return $data;
55
-        }
56
-        catch (SocketError $e) {
55
+        } catch (SocketError $e) {
57 56
             $e->setExtra($data);
58 57
             throw $e;
59 58
         }
@@ -90,8 +89,7 @@  discard block
 block discarded – undo
90 89
         $length = $this->getOption(SO_RCVBUF);
91 90
         try {
92 91
             return $this->recv($length, $flags);
93
-        }
94
-        catch (SocketError $e) {
92
+        } catch (SocketError $e) {
95 93
             if ($e->getCode() === SOCKET_EAGAIN) { // would block
96 94
                 return '';
97 95
             }
Please login to merge, or discard this patch.
src/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,17 +125,17 @@  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
 
132 132
     /**
133 133
      * Servers never get OOB data.
134 134
      */
135
-    final public function onOutOfBand (): void {
135
+    final public function onOutOfBand(): void {
136 136
     }
137 137
 
138
-    public function onReadable (): void {
138
+    public function onReadable(): void {
139 139
         $this->accept();
140 140
     }
141 141
 
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
      *
145 145
      * @param WebSocketClient $client
146 146
      */
147
-    public function remove (WebSocketClient $client) {
147
+    public function remove(WebSocketClient $client) {
148 148
         unset($this->clients[$client->getId()]);
149 149
         $this->reactor->remove($client);
150 150
     }
Please login to merge, or discard this patch.
src/WebSocket/FrameHandler.php 2 patches
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -46,21 +46,21 @@  discard block
 block discarded – undo
46 46
      */
47 47
     protected $maxLength = 10 * 1024 * 1024;
48 48
 
49
-    public function __construct (WebSocketClient $client) {
49
+    public function __construct(WebSocketClient $client) {
50 50
         $this->client = $client;
51 51
     }
52 52
 
53 53
     /**
54 54
      * @return int
55 55
      */
56
-    public function getFragmentSize (): int {
56
+    public function getFragmentSize(): int {
57 57
         return $this->fragmentSize;
58 58
     }
59 59
 
60 60
     /**
61 61
      * @return int
62 62
      */
63
-    public function getMaxLength (): int {
63
+    public function getMaxLength(): int {
64 64
         return $this->maxLength;
65 65
     }
66 66
 
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
      * @param Frame $binary
73 73
      * @throws WebSocketError
74 74
      */
75
-    protected function onBinary (Frame $binary): void {
75
+    protected function onBinary(Frame $binary): void {
76 76
         $this->buffer .= $binary->getPayload();
77 77
         if ($binary->isFinal()) {
78 78
             $message = $this->buffer;
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
      *
93 93
      * @param Frame $close
94 94
      */
95
-    protected function onClose (Frame $close): void {
95
+    protected function onClose(Frame $close): void {
96 96
         $this->client->close($close->getCloseCode());
97 97
     }
98 98
 
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
      * @param Frame $frame
103 103
      * @throws WebSocketError
104 104
      */
105
-    protected function onContinue (Frame $frame): void {
105
+    protected function onContinue(Frame $frame): void {
106 106
         try {
107 107
             switch ($this->continue) {
108 108
                 case Frame::OP_TEXT:
@@ -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
         $this->onData_SetContinue($data);
157 157
         if ($data->isText()) {
158 158
             $this->onText($data);
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
         }
163 163
     }
164 164
 
165
-    protected function onData_SetContinue (Frame $data): void {
165
+    protected function onData_SetContinue(Frame $data): void {
166 166
         if ($this->continue) {
167 167
             $existing = Frame::NAMES[$this->continue];
168 168
             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
             $length = strlen($this->buffer);
206 206
             if ($length + $frame->getLength() > $this->maxLength) {
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
      * @param Frame $frame
220 220
      * @throws WebSocketError
221 221
      */
222
-    protected function onFrame_CheckRsv (Frame $frame): void {
222
+    protected function onFrame_CheckRsv(Frame $frame): void {
223 223
         if ($badRsv = $frame->getRsv() & ~$this->client->getHandshake()->getRsv()) {
224 224
             $badRsv = str_pad(base_convert($badRsv >> 4, 10, 2), 3, '0', STR_PAD_LEFT);
225 225
             throw new WebSocketError(Frame::CLOSE_PROTOCOL_ERROR, "Received unknown RSV bits: 0b{$badRsv}");
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
      *
234 234
      * @param Frame $ping
235 235
      */
236
-    protected function onPing (Frame $ping): void {
236
+    protected function onPing(Frame $ping): void {
237 237
         $this->writePong($ping->getPayload());
238 238
     }
239 239
 
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
      *
245 245
      * @param Frame $pong
246 246
      */
247
-    protected function onPong (Frame $pong): void {
247
+    protected function onPong(Frame $pong): void {
248 248
         // stub
249 249
     }
250 250
 
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
      * @param Frame $text
257 257
      * @throws WebSocketError
258 258
      */
259
-    protected function onText (Frame $text): void {
259
+    protected function onText(Frame $text): void {
260 260
         $this->buffer .= $text->getPayload();
261 261
         if ($text->isFinal()) {
262 262
             $message = $this->buffer;
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
      * @param int $bytes
270 270
      * @return $this
271 271
      */
272
-    public function setFragmentSize (int $bytes) {
272
+    public function setFragmentSize(int $bytes) {
273 273
         $this->fragmentSize = $bytes;
274 274
         return $this;
275 275
     }
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
      * @param int $bytes
279 279
      * @return $this
280 280
      */
281
-    public function setMaxLength (int $bytes) {
281
+    public function setMaxLength(int $bytes) {
282 282
         $this->maxLength = $bytes;
283 283
         return $this;
284 284
     }
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
      * @param int $opCode
290 290
      * @param string $payload
291 291
      */
292
-    public function write (int $opCode, string $payload): void {
292
+    public function write(int $opCode, string $payload): void {
293 293
         $offset = 0;
294 294
         $total = strlen($payload);
295 295
         do {
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
     /**
306 306
      * @param string $payload
307 307
      */
308
-    public function writeBinary (string $payload): void {
308
+    public function writeBinary(string $payload): void {
309 309
         $this->write(Frame::OP_BINARY, $payload);
310 310
     }
311 311
 
@@ -313,8 +313,8 @@  discard block
 block discarded – undo
313 313
      * @param int $code
314 314
      * @param string $reason
315 315
      */
316
-    public function writeClose (int $code = Frame::CLOSE_NORMAL, string $reason = ''): void {
317
-        $this->writeFrame(true, Frame::OP_CLOSE, pack('n', $code) . $reason);
316
+    public function writeClose(int $code = Frame::CLOSE_NORMAL, string $reason = ''): void {
317
+        $this->writeFrame(true, Frame::OP_CLOSE, pack('n', $code).$reason);
318 318
     }
319 319
 
320 320
     /**
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
      * @param int $opCode
325 325
      * @param string $payload
326 326
      */
327
-    protected function writeFrame (bool $final, int $opCode, string $payload): void {
327
+    protected function writeFrame(bool $final, int $opCode, string $payload): void {
328 328
         if ($opCode & 0x08 and !$final) {
329 329
             throw new WebSocketError(
330 330
                 Frame::CLOSE_INTERNAL_ERROR,
@@ -344,27 +344,27 @@  discard block
 block discarded – undo
344 344
         else {
345 345
             $head .= chr($length);
346 346
         }
347
-        $this->client->write($head . $payload);
347
+        $this->client->write($head.$payload);
348 348
     }
349 349
 
350 350
     /**
351 351
      * @param string $payload
352 352
      */
353
-    public function writePing (string $payload = ''): void {
353
+    public function writePing(string $payload = ''): void {
354 354
         $this->writeFrame(true, Frame::OP_PING, $payload);
355 355
     }
356 356
 
357 357
     /**
358 358
      * @param string $payload
359 359
      */
360
-    public function writePong (string $payload = ''): void {
360
+    public function writePong(string $payload = ''): void {
361 361
         $this->writeFrame(true, Frame::OP_PONG, $payload);
362 362
     }
363 363
 
364 364
     /**
365 365
      * @param string $payload
366 366
      */
367
-    public function writeText (string $payload): void {
367
+    public function writeText(string $payload): void {
368 368
         $this->write(Frame::OP_TEXT, $payload);
369 369
     }
370 370
 }
371 371
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +8 added lines, -16 removed lines patch added patch discarded remove patch
@@ -118,8 +118,7 @@  discard block
 block discarded – undo
118 118
                         $frame
119 119
                     );
120 120
             }
121
-        }
122
-        finally {
121
+        } finally {
123 122
             if ($frame->isFinal()) {
124 123
                 $this->continue = null;
125 124
             }
@@ -138,11 +137,9 @@  discard block
 block discarded – undo
138 137
     protected function onControl (Frame $control): void {
139 138
         if ($control->isClose()) {
140 139
             $this->onClose($control);
141
-        }
142
-        elseif ($control->isPing()) {
140
+        } elseif ($control->isPing()) {
143 141
             $this->onPing($control);
144
-        }
145
-        elseif ($control->isPong()) {
142
+        } elseif ($control->isPong()) {
146 143
             $this->onPong($control);
147 144
         }
148 145
     }
@@ -156,8 +153,7 @@  discard block
 block discarded – undo
156 153
         $this->onData_SetContinue($data);
157 154
         if ($data->isText()) {
158 155
             $this->onText($data);
159
-        }
160
-        elseif ($data->isBinary()) {
156
+        } elseif ($data->isBinary()) {
161 157
             $this->onBinary($data);
162 158
         }
163 159
     }
@@ -188,11 +184,9 @@  discard block
 block discarded – undo
188 184
         $this->onFrame_CheckLength($frame);
189 185
         if ($frame->isControl()) {
190 186
             $this->onControl($frame);
191
-        }
192
-        elseif ($frame->isContinue()) {
187
+        } elseif ($frame->isContinue()) {
193 188
             $this->onContinue($frame);
194
-        }
195
-        else {
189
+        } else {
196 190
             $this->onData($frame);
197 191
         }
198 192
     }
@@ -336,12 +330,10 @@  discard block
 block discarded – undo
336 330
         if ($length > 65535) {
337 331
             $head .= chr(127);
338 332
             $head .= pack('J', $length);
339
-        }
340
-        elseif ($length >= 126) {
333
+        } elseif ($length >= 126) {
341 334
             $head .= chr(126);
342 335
             $head .= pack('n', $length);
343
-        }
344
-        else {
336
+        } else {
345 337
             $head .= chr($length);
346 338
         }
347 339
         $this->client->write($head . $payload);
Please login to merge, or discard this patch.