@@ -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 | } |
@@ -84,8 +84,7 @@ discard block |
||
84 | 84 | unset($channel); |
85 | 85 | if ($socket instanceof WebSocketClient and $error instanceof WebSocketError) { |
86 | 86 | $socket->close($error->getCode(), $error->getMessage()); |
87 | - } |
|
88 | - else { |
|
87 | + } else { |
|
89 | 88 | $socket->close(); |
90 | 89 | } |
91 | 90 | echo $error; |
@@ -109,11 +108,9 @@ discard block |
||
109 | 108 | foreach ($rwe[$channel] as $id => $socket) { |
110 | 109 | try { |
111 | 110 | $socket->{$method}(); |
112 | - } |
|
113 | - catch (Throwable $error) { |
|
111 | + } catch (Throwable $error) { |
|
114 | 112 | $this->onError($channel, $socket, $error); |
115 | - } |
|
116 | - finally { |
|
113 | + } finally { |
|
117 | 114 | if (!$socket->isOpen()) { |
118 | 115 | $this->remove($socket); |
119 | 116 | } |
@@ -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 | } |
@@ -101,19 +101,16 @@ |
||
101 | 101 | $value = trim($value); |
102 | 102 | if (isset($this->headers[$key])) { |
103 | 103 | $this->headers[$key] .= ', ' . $value; |
104 | - } |
|
105 | - else { |
|
104 | + } else { |
|
106 | 105 | $this->headers[$key] = $value; |
107 | 106 | } |
108 | 107 | } |
109 | 108 | $this->buffer = ''; // wipe the buffer |
110 | 109 | $this->validate(); |
111 | - } |
|
112 | - catch (WebSocketError $e) { // catch and respond with HTTP error and rethrow |
|
110 | + } catch (WebSocketError $e) { // catch and respond with HTTP error and rethrow |
|
113 | 111 | $this->client->write("HTTP/1.1 {$e->getCode()} WebSocket Handshake Failure\r\n\r\n"); |
114 | 112 | throw $e; |
115 | - } |
|
116 | - catch (Throwable $e) { // catch everything else and respond with HTTP 500 and rethrow |
|
113 | + } catch (Throwable $e) { // catch everything else and respond with HTTP 500 and rethrow |
|
117 | 114 | $this->client->write("HTTP/1.1 500 WebSocket Internal Error\r\n\r\n"); |
118 | 115 | throw $e; |
119 | 116 | } |
@@ -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 | } |