@@ -93,8 +93,7 @@ |
||
| 93 | 93 | foreach ($rwe[0] as $id => $socket) { |
| 94 | 94 | $socket->onReadable(); |
| 95 | 95 | } |
| 96 | - } |
|
| 97 | - finally { |
|
| 96 | + } finally { |
|
| 98 | 97 | array_walk_recursive($rwe, function(ReactiveInterface $each) { |
| 99 | 98 | if (!$each->isOpen()) { |
| 100 | 99 | $this->remove($each); |
@@ -91,8 +91,7 @@ discard block |
||
| 91 | 91 | $value = trim($value); |
| 92 | 92 | if (isset($this->headers[$key])) { |
| 93 | 93 | $this->headers[$key] .= ', ' . $value; |
| 94 | - } |
|
| 95 | - else { |
|
| 94 | + } else { |
|
| 96 | 95 | $this->headers[$key] = $value; |
| 97 | 96 | } |
| 98 | 97 | } |
@@ -101,8 +100,7 @@ discard block |
||
| 101 | 100 | $this->upgrade(); |
| 102 | 101 | $this->client->write("\r\n\r\n"); |
| 103 | 102 | return true; |
| 104 | - } |
|
| 105 | - catch (WebSocketError $e) { |
|
| 103 | + } catch (WebSocketError $e) { |
|
| 106 | 104 | $this->client->write("HTTP/1.1 {$e->getCode()}\r\n\r\n"); |
| 107 | 105 | throw $e; |
| 108 | 106 | } |
@@ -94,8 +94,7 @@ |
||
| 94 | 94 | foreach ($this->clients as $client) { |
| 95 | 95 | try { |
| 96 | 96 | $client->close($code, $reason); |
| 97 | - } |
|
| 98 | - catch (Exception $e) { |
|
| 97 | + } catch (Exception $e) { |
|
| 99 | 98 | continue; |
| 100 | 99 | } |
| 101 | 100 | } |
@@ -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 | } |
@@ -23,7 +23,7 @@ |
||
| 23 | 23 | * @link https://php.net/socket_create_pair |
| 24 | 24 | * |
| 25 | 25 | * @param array $extra Variadic constructor arguments. |
| 26 | - * @return static[] Two instances at indices `0` and `1`. |
|
| 26 | + * @return StreamClient[] Two instances at indices `0` and `1`. |
|
| 27 | 27 | * @throws SocketError |
| 28 | 28 | */ |
| 29 | 29 | public static function newUnixPair (...$extra) { |
@@ -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 | } |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * @link https://php.net/socket_get_option |
| 155 | 155 | * |
| 156 | 156 | * @param int $option `SO_*` option constant. |
| 157 | - * @return mixed The option's value. This is never `false`. |
|
| 157 | + * @return integer The option's value. This is never `false`. |
|
| 158 | 158 | * @throws SocketError |
| 159 | 159 | */ |
| 160 | 160 | public function getOption (int $option) { |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | * @see await() |
| 223 | 223 | * |
| 224 | 224 | * @param int $channel `SocketInterface` channel constant. |
| 225 | - * @param float|null $timeout Maximum seconds to block. `NULL` blocks forever. Defaults to a poll. |
|
| 225 | + * @param integer $timeout Maximum seconds to block. `NULL` blocks forever. Defaults to a poll. |
|
| 226 | 226 | * @return bool |
| 227 | 227 | * @throws SocketError |
| 228 | 228 | */ |
@@ -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 | } |