@@ -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']}"; |
@@ -53,8 +53,7 @@ discard block |
||
53 | 53 | $length -= $chunkSize = strlen($chunk); |
54 | 54 | } while ($chunkSize and $length); |
55 | 55 | return $data; |
56 | - } |
|
57 | - catch (SocketError $e) { |
|
56 | + } catch (SocketError $e) { |
|
58 | 57 | $e->setExtra($data); |
59 | 58 | throw $e; |
60 | 59 | } |
@@ -91,8 +90,7 @@ discard block |
||
91 | 90 | $length = $this->getOption(SO_RCVBUF); |
92 | 91 | try { |
93 | 92 | return $this->recv($length, $msgFlags); |
94 | - } |
|
95 | - catch (SocketError $e) { |
|
93 | + } catch (SocketError $e) { |
|
96 | 94 | if ($e->getCode() === SOCKET_EAGAIN) { // would block |
97 | 95 | return ''; |
98 | 96 | } |
@@ -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 | } |
@@ -138,11 +138,9 @@ discard block |
||
138 | 138 | protected function onControl (Frame $control): void { |
139 | 139 | if ($control->isClose()) { |
140 | 140 | $this->onClose($control); |
141 | - } |
|
142 | - elseif ($control->isPing()) { |
|
141 | + } elseif ($control->isPing()) { |
|
143 | 142 | $this->onPing($control); |
144 | - } |
|
145 | - elseif ($control->isPong()) { |
|
143 | + } elseif ($control->isPong()) { |
|
146 | 144 | $this->onPong($control); |
147 | 145 | } |
148 | 146 | } |
@@ -158,8 +156,7 @@ discard block |
||
158 | 156 | } |
159 | 157 | if ($data->isText()) { |
160 | 158 | $this->onText($data); |
161 | - } |
|
162 | - elseif ($data->isBinary()) { |
|
159 | + } elseif ($data->isBinary()) { |
|
163 | 160 | $this->onBinary($data); |
164 | 161 | } |
165 | 162 | } |
@@ -188,11 +185,9 @@ discard block |
||
188 | 185 | $this->onFrame_CheckLength($frame); |
189 | 186 | if ($frame->isControl()) { |
190 | 187 | $this->onControl($frame); |
191 | - } |
|
192 | - elseif ($frame->isContinue()) { |
|
188 | + } elseif ($frame->isContinue()) { |
|
193 | 189 | $this->onContinue($frame); |
194 | - } |
|
195 | - else { |
|
190 | + } else { |
|
196 | 191 | $this->onData($frame); |
197 | 192 | } |
198 | 193 | } |
@@ -204,8 +199,7 @@ discard block |
||
204 | 199 | if ($frame->isData()) { |
205 | 200 | if ($frame->isBinary()) { |
206 | 201 | $length = strlen($this->binary); |
207 | - } |
|
208 | - else { |
|
202 | + } else { |
|
209 | 203 | $length = strlen($this->text); |
210 | 204 | } |
211 | 205 | if ($length + $frame->getLength() > $this->maxLength) { |
@@ -341,12 +335,10 @@ discard block |
||
341 | 335 | if ($length > 65535) { |
342 | 336 | $head .= chr(127); |
343 | 337 | $head .= pack('J', $length); |
344 | - } |
|
345 | - elseif ($length >= 126) { |
|
338 | + } elseif ($length >= 126) { |
|
346 | 339 | $head .= chr(126); |
347 | 340 | $head .= pack('n', $length); |
348 | - } |
|
349 | - else { |
|
341 | + } else { |
|
350 | 342 | $head .= chr($length); |
351 | 343 | } |
352 | 344 | $this->client->write($head . $payload); |
@@ -80,8 +80,7 @@ discard block |
||
80 | 80 | $this->getFrameHandler()->writeClose($code, $reason); |
81 | 81 | $this->shutdown(self::CH_WRITE); |
82 | 82 | } |
83 | - } |
|
84 | - finally { |
|
83 | + } finally { |
|
85 | 84 | $this->state = self::STATE_CLOSE; |
86 | 85 | $this->server->remove($this); |
87 | 86 | parent::close(); |
@@ -173,12 +172,10 @@ discard block |
||
173 | 172 | case self::STATE_CLOSE: |
174 | 173 | return; |
175 | 174 | } |
176 | - } |
|
177 | - catch (WebSocketError $e) { |
|
175 | + } catch (WebSocketError $e) { |
|
178 | 176 | $this->close($e->getCode(), $e->getMessage()); |
179 | 177 | throw $e; |
180 | - } |
|
181 | - catch (Exception $e) { |
|
178 | + } catch (Exception $e) { |
|
182 | 179 | $this->close(Frame::CLOSE_INTERNAL_ERROR); |
183 | 180 | throw $e; |
184 | 181 | } |
@@ -67,11 +67,9 @@ discard block |
||
67 | 67 | ]; |
68 | 68 | $this->buffer = substr($this->buffer, strlen($head[0])); |
69 | 69 | $this->validate(); |
70 | - } |
|
71 | - elseif (strlen($this->buffer) >= 14) { // max head room |
|
70 | + } elseif (strlen($this->buffer) >= 14) { // max head room |
|
72 | 71 | throw new WebSocketError(Frame::CLOSE_PROTOCOL_ERROR, 'Bad frame.'); |
73 | - } |
|
74 | - else { |
|
72 | + } else { |
|
75 | 73 | return null; |
76 | 74 | } |
77 | 75 | } |
@@ -139,8 +137,7 @@ discard block |
||
139 | 137 | if (!$this->head['final']) { |
140 | 138 | throw new WebSocketError(Frame::CLOSE_PROTOCOL_ERROR, "Received fragmented {$name}"); |
141 | 139 | } |
142 | - } |
|
143 | - elseif ($opCode > Frame::OP_BINARY) { // data |
|
140 | + } elseif ($opCode > Frame::OP_BINARY) { // data |
|
144 | 141 | throw new WebSocketError(Frame::CLOSE_PROTOCOL_ERROR, "Received {$name}"); |
145 | 142 | } |
146 | 143 | } |
@@ -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 | } |