@@ -21,8 +21,7 @@ discard block |
||
21 | 21 | public function __toString () { |
22 | 22 | try { |
23 | 23 | return implode(':', $this->getPeerName()); |
24 | - } |
|
25 | - catch (Throwable $e) { |
|
24 | + } catch (Throwable $e) { |
|
26 | 25 | return "?{$this->resource}"; |
27 | 26 | } |
28 | 27 | } |
@@ -102,8 +101,7 @@ discard block |
||
102 | 101 | while ($total < $length) { |
103 | 102 | try { |
104 | 103 | $total += $this->awaitWritable()->send(substr($data, $total)); |
105 | - } |
|
106 | - catch (SocketError $e) { |
|
104 | + } catch (SocketError $e) { |
|
107 | 105 | $e->setExtra($total); |
108 | 106 | throw $e; |
109 | 107 | } |
@@ -65,8 +65,7 @@ |
||
65 | 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 | - } |
|
69 | - else { |
|
68 | + } else { |
|
70 | 69 | $errno = $fallback; |
71 | 70 | $last = error_get_last(); |
72 | 71 | $message = "{$last['message']} in {$last['file']}:{$last['line']}"; |
@@ -52,11 +52,9 @@ |
||
52 | 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 | - } |
|
56 | - elseif (socket_get_option($resource, SOL_SOCKET, SO_TYPE) !== static::getType()) { |
|
55 | + } elseif (socket_get_option($resource, SOL_SOCKET, SO_TYPE) !== static::getType()) { |
|
57 | 56 | throw new InvalidArgumentException('Invalid socket type for ' . static::class, SOCKET_ESOCKTNOSUPPORT); |
58 | - } |
|
59 | - elseif ($errno = SocketError::getLast($resource)) { |
|
57 | + } elseif ($errno = SocketError::getLast($resource)) { |
|
60 | 58 | // "File descriptor in bad state" |
61 | 59 | throw new SocketError(SOCKET_EBADFD, 0, new SocketError($errno)); |
62 | 60 | } |
@@ -21,8 +21,7 @@ |
||
21 | 21 | public function __toString () { |
22 | 22 | try { |
23 | 23 | return implode(':', $this->getSockName()); |
24 | - } |
|
25 | - catch (Throwable $e) { |
|
24 | + } catch (Throwable $e) { |
|
26 | 25 | return "?{$this->resource}"; |
27 | 26 | } |
28 | 27 | } |
@@ -52,8 +52,7 @@ discard block |
||
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 |
||
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 | } |
@@ -101,8 +101,7 @@ |
||
101 | 101 | foreach ($this->clients as $client) { |
102 | 102 | try { |
103 | 103 | $client->close($code, $reason); // clients remove themselves |
104 | - } |
|
105 | - catch (Exception $e) { |
|
104 | + } catch (Exception $e) { |
|
106 | 105 | continue; |
107 | 106 | } |
108 | 107 | } |
@@ -82,8 +82,7 @@ discard block |
||
82 | 82 | if ($code >= 1000 and $this->isOk()) { |
83 | 83 | $this->frameHandler->writeClose($code, $reason); |
84 | 84 | } |
85 | - } |
|
86 | - finally { |
|
85 | + } finally { |
|
87 | 86 | $this->server->remove($this); |
88 | 87 | parent::close(); |
89 | 88 | $this->state = self::STATE_CLOSED; |
@@ -200,16 +199,13 @@ discard block |
||
200 | 199 | $this->state = self::STATE_OK; |
201 | 200 | $this->onStateOk(); |
202 | 201 | } |
203 | - } |
|
204 | - elseif ($this->isOk()) { |
|
202 | + } elseif ($this->isOk()) { |
|
205 | 203 | $this->frameHandler->onReadable(); |
206 | 204 | } |
207 | - } |
|
208 | - catch (WebSocketError $e) { |
|
205 | + } catch (WebSocketError $e) { |
|
209 | 206 | $this->close($e->getCode(), $e->getMessage()); |
210 | 207 | throw $e; |
211 | - } |
|
212 | - catch (Throwable $e) { |
|
208 | + } catch (Throwable $e) { |
|
213 | 209 | $this->close(Frame::CLOSE_INTERNAL_ERROR); |
214 | 210 | throw $e; |
215 | 211 | } |
@@ -141,19 +141,15 @@ |
||
141 | 141 | if ($badRsv = $rsv & ~$this->rsv) { |
142 | 142 | $badRsv = str_pad(base_convert($badRsv >> 4, 10, 2), 3, '0', STR_PAD_LEFT); |
143 | 143 | throw new WebSocketError(Frame::CLOSE_PROTOCOL_ERROR, "Received unknown RSV bits: 0b{$badRsv}"); |
144 | - } |
|
145 | - elseif ($opCode >= Frame::OP_CLOSE) { |
|
144 | + } elseif ($opCode >= Frame::OP_CLOSE) { |
|
146 | 145 | if ($opCode > Frame::OP_PONG) { |
147 | 146 | throw new WebSocketError(Frame::CLOSE_PROTOCOL_ERROR, "Received unsupported control frame ({$opCode})"); |
148 | - } |
|
149 | - elseif (!$final) { |
|
147 | + } elseif (!$final) { |
|
150 | 148 | throw new WebSocketError(Frame::CLOSE_PROTOCOL_ERROR, "Received fragmented control frame ({$opCode})"); |
151 | 149 | } |
152 | - } |
|
153 | - elseif ($opCode > Frame::OP_BINARY) { |
|
150 | + } elseif ($opCode > Frame::OP_BINARY) { |
|
154 | 151 | throw new WebSocketError(Frame::CLOSE_PROTOCOL_ERROR, "Received unsupported data frame ({$opCode})"); |
155 | - } |
|
156 | - elseif ($length > $this->maxLength) { |
|
152 | + } elseif ($length > $this->maxLength) { |
|
157 | 153 | throw new WebSocketError(Frame::CLOSE_TOO_LARGE, "Payload would exceed {$this->maxLength} bytes"); |
158 | 154 | } |
159 | 155 |
@@ -105,8 +105,7 @@ discard block |
||
105 | 105 | protected function onBinary (Frame $frame): void { |
106 | 106 | if ($this->stream) { |
107 | 107 | $this->client->onBinary($frame->getPayload()); |
108 | - } |
|
109 | - else { |
|
108 | + } else { |
|
110 | 109 | $this->onData_CheckLength($frame); |
111 | 110 | $this->buffer .= $frame->getPayload(); |
112 | 111 | if ($frame->isFinal()) { |
@@ -149,12 +148,10 @@ discard block |
||
149 | 148 | try { |
150 | 149 | if ($this->continue === Frame::OP_TEXT) { |
151 | 150 | $this->onText($frame); |
152 | - } |
|
153 | - else { |
|
151 | + } else { |
|
154 | 152 | $this->onBinary($frame); |
155 | 153 | } |
156 | - } |
|
157 | - finally { |
|
154 | + } finally { |
|
158 | 155 | if ($frame->isFinal()) { |
159 | 156 | $this->continue = null; |
160 | 157 | } |
@@ -173,14 +170,11 @@ discard block |
||
173 | 170 | protected function onControl (Frame $frame): void { |
174 | 171 | if ($frame->isClose()) { |
175 | 172 | $this->onClose($frame); |
176 | - } |
|
177 | - elseif ($frame->isPing()) { |
|
173 | + } elseif ($frame->isPing()) { |
|
178 | 174 | $this->onPing($frame); |
179 | - } |
|
180 | - elseif ($frame->isPong()) { |
|
175 | + } elseif ($frame->isPong()) { |
|
181 | 176 | $this->onPong($frame); |
182 | - } |
|
183 | - else { |
|
177 | + } else { |
|
184 | 178 | throw new WebSocketError(Frame::CLOSE_PROTOCOL_ERROR, "Unsupported control frame.", $frame); |
185 | 179 | } |
186 | 180 | } |
@@ -248,8 +242,7 @@ discard block |
||
248 | 242 | public function onFrame (Frame $frame): void { |
249 | 243 | if ($frame->isControl()) { |
250 | 244 | $this->onControl($frame); |
251 | - } |
|
252 | - else { |
|
245 | + } else { |
|
253 | 246 | $this->onData($frame); |
254 | 247 | } |
255 | 248 | } |
@@ -378,12 +371,10 @@ discard block |
||
378 | 371 | if ($length > 65535) { |
379 | 372 | $head .= chr(127); |
380 | 373 | $head .= pack('J', $length); |
381 | - } |
|
382 | - elseif ($length >= 126) { |
|
374 | + } elseif ($length >= 126) { |
|
383 | 375 | $head .= chr(126); |
384 | 376 | $head .= pack('n', $length); |
385 | - } |
|
386 | - else { |
|
377 | + } else { |
|
387 | 378 | $head .= chr($length); |
388 | 379 | } |
389 | 380 | $this->client->write($head . $payload); |