@@ -12,7 +12,7 @@ |
||
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_DGRAM; |
17 | 17 | } |
18 | 18 |
@@ -14,13 +14,13 @@ |
||
14 | 14 | * |
15 | 15 | * @return void |
16 | 16 | */ |
17 | - public function onOutOfBand (): void; |
|
17 | + public function onOutOfBand(): void; |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * Called by the reactor when the socket has readable data. |
21 | 21 | * |
22 | 22 | * @return void |
23 | 23 | */ |
24 | - public function onReadable (): void; |
|
24 | + public function onReadable(): void; |
|
25 | 25 | |
26 | 26 | } |
27 | 27 | \ No newline at end of file |
@@ -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 | } |
@@ -48,28 +48,28 @@ discard block |
||
48 | 48 | /** |
49 | 49 | * @param WebSocketClient $client |
50 | 50 | */ |
51 | - public function __construct (WebSocketClient $client) { |
|
51 | + public function __construct(WebSocketClient $client) { |
|
52 | 52 | $this->client = $client; |
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
56 | 56 | * @return string[] |
57 | 57 | */ |
58 | - public function getHeaders () { |
|
58 | + public function getHeaders() { |
|
59 | 59 | return $this->headers; |
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
63 | 63 | * @return string |
64 | 64 | */ |
65 | - public function getMethod (): string { |
|
65 | + public function getMethod(): string { |
|
66 | 66 | return $this->method; |
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
70 | 70 | * @return int |
71 | 71 | */ |
72 | - public function getRsv (): int { |
|
72 | + public function getRsv(): int { |
|
73 | 73 | return $this->rsv; |
74 | 74 | } |
75 | 75 | |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @return bool |
80 | 80 | * @throws WebSocketError |
81 | 81 | */ |
82 | - public function negotiate (): bool { |
|
82 | + public function negotiate(): bool { |
|
83 | 83 | $this->buffer .= $this->client->recvAll(); |
84 | 84 | try { |
85 | 85 | if (strlen($this->buffer) > $this->sizeLimit) { |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | $key = strtolower(trim($key)); |
100 | 100 | $value = trim($value); |
101 | 101 | if (isset($this->headers[$key])) { |
102 | - $this->headers[$key] .= ', ' . $value; |
|
102 | + $this->headers[$key] .= ', '.$value; |
|
103 | 103 | } |
104 | 104 | else { |
105 | 105 | $this->headers[$key] = $value; |
@@ -120,12 +120,12 @@ discard block |
||
120 | 120 | /** |
121 | 121 | * Sends the connection upgrade headers. |
122 | 122 | */ |
123 | - protected function upgrade (): void { |
|
123 | + protected function upgrade(): void { |
|
124 | 124 | $this->client->write(implode("\r\n", [ |
125 | 125 | "HTTP/1.1 101 Switching Protocols", |
126 | 126 | "Connection: Upgrade", |
127 | 127 | "Upgrade: websocket", |
128 | - "Sec-WebSocket-Accept: " . base64_encode(sha1($this->headers['sec-websocket-key'] . self::RFC_GUID, true)), |
|
128 | + "Sec-WebSocket-Accept: ".base64_encode(sha1($this->headers['sec-websocket-key'].self::RFC_GUID, true)), |
|
129 | 129 | ])); |
130 | 130 | } |
131 | 131 | |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | * |
135 | 135 | * @throws WebSocketError |
136 | 136 | */ |
137 | - protected function validate (): void { |
|
137 | + protected function validate(): void { |
|
138 | 138 | if (!( |
139 | 139 | $check = 'method = http 1.1' |
140 | 140 | and preg_match('/HTTP\/1\.1$/i', $this->method) |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | */ |
26 | 26 | protected $frame; |
27 | 27 | |
28 | - public function __construct (int $code, string $message = '', Frame $frame = null, Throwable $previous = null) { |
|
28 | + public function __construct(int $code, string $message = '', Frame $frame = null, Throwable $previous = null) { |
|
29 | 29 | parent::__construct($message, $code, $previous); |
30 | 30 | $this->frame = $frame; |
31 | 31 | } |
@@ -33,14 +33,14 @@ discard block |
||
33 | 33 | /** |
34 | 34 | * @return mixed |
35 | 35 | */ |
36 | - public function getExtra () { |
|
36 | + public function getExtra() { |
|
37 | 37 | return $this->extra; |
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
41 | 41 | * @return Frame|null |
42 | 42 | */ |
43 | - public function getFrame () { |
|
43 | + public function getFrame() { |
|
44 | 44 | return $this->frame; |
45 | 45 | } |
46 | 46 | |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * @param mixed $extra |
49 | 49 | * @return $this |
50 | 50 | */ |
51 | - public function setExtra ($extra) { |
|
51 | + public function setExtra($extra) { |
|
52 | 52 | $this->extra = $extra; |
53 | 53 | return $this; |
54 | 54 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * |
19 | 19 | * @return string |
20 | 20 | */ |
21 | - public function __toString () { |
|
21 | + public function __toString() { |
|
22 | 22 | try { |
23 | 23 | return implode(':', $this->getPeerName()); |
24 | 24 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * @return $this |
42 | 42 | * @throws SocketError |
43 | 43 | */ |
44 | - public function connect (string $address, int $port = 0) { |
|
44 | + public function connect(string $address, int $port = 0) { |
|
45 | 45 | if (!@socket_connect($this->resource, $address, $port)) { |
46 | 46 | // ignore expected errors for non-blocking connections |
47 | 47 | $errno = SocketError::getLast($this->resource); |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * @return array `[ 0 => address, 1 => port ]` |
62 | 62 | * @throws SocketError |
63 | 63 | */ |
64 | - public function getPeerName (): array { |
|
64 | + public function getPeerName(): array { |
|
65 | 65 | if ($this->getDomain() === AF_UNIX) { |
66 | 66 | return [$this->getOption(17), 0]; // SO_PEERCRED is not exposed by PHP |
67 | 67 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | * @return int Total bytes sent. |
82 | 82 | * @throws SocketError |
83 | 83 | */ |
84 | - public function send (string $data, int $flags = 0): int { |
|
84 | + public function send(string $data, int $flags = 0): int { |
|
85 | 85 | $count = @socket_send($this->resource, $data, strlen($data), $flags); |
86 | 86 | if ($count === false) { |
87 | 87 | throw new SocketError($this->resource); // reliable errno |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * @return $this |
97 | 97 | * @throws SocketError `int` total bytes sent is set as the extra data. |
98 | 98 | */ |
99 | - public function write (string $data) { |
|
99 | + public function write(string $data) { |
|
100 | 100 | $length = strlen($data); |
101 | 101 | $total = 0; |
102 | 102 | while ($total < $length) { |
@@ -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 | } |
@@ -27,20 +27,20 @@ |
||
27 | 27 | * |
28 | 28 | * @return int |
29 | 29 | */ |
30 | - public function getId (): int; |
|
30 | + public function getId(): int; |
|
31 | 31 | |
32 | 32 | /** |
33 | 33 | * Returns the underlying socket resource. |
34 | 34 | * |
35 | 35 | * @return resource |
36 | 36 | */ |
37 | - public function getResource (); |
|
37 | + public function getResource(); |
|
38 | 38 | |
39 | 39 | /** |
40 | 40 | * Whether the underlying resource is usable. |
41 | 41 | * |
42 | 42 | * @return bool |
43 | 43 | */ |
44 | - public function isOpen (): bool; |
|
44 | + public function isOpen(): bool; |
|
45 | 45 | |
46 | 46 | } |
47 | 47 | \ No newline at end of file |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @param resource $resource PHP socket resource, or `null` for the global error. |
30 | 30 | * @return int If the resource is closed or not a socket, `SOCKET_EBADF` is returned. |
31 | 31 | */ |
32 | - public static function getLast ($resource = null) { |
|
32 | + public static function getLast($resource = null) { |
|
33 | 33 | if (isset($resource)) { |
34 | 34 | if (@get_resource_type($resource) !== 'Socket') { |
35 | 35 | return SOCKET_EBADF; // Bad file descriptor |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * @param int $fallback Code to assume if one can't be found via the subject. |
63 | 63 | * @param SocketError|null $previous Slippage of a prior error. |
64 | 64 | */ |
65 | - public function __construct ($subject = null, $fallback = 0, SocketError $previous = null) { |
|
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 | 68 | } |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | /** |
78 | 78 | * @return mixed |
79 | 79 | */ |
80 | - public function getExtra () { |
|
80 | + public function getExtra() { |
|
81 | 81 | return $this->extra; |
82 | 82 | } |
83 | 83 | |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * @param mixed $extra |
86 | 86 | * @return $this |
87 | 87 | */ |
88 | - public function setExtra ($extra) { |
|
88 | + public function setExtra($extra) { |
|
89 | 89 | $this->extra = $extra; |
90 | 90 | return $this; |
91 | 91 | } |
@@ -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 | } |
@@ -151,7 +151,7 @@ discard block |
||
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 |
||
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 | */ |
@@ -14,7 +14,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | * |
130 | 130 | * @return $this |
131 | 131 | */ |
132 | - public function close () { |
|
132 | + public function close() { |
|
133 | 133 | socket_close($this->resource); |
134 | 134 | return $this; |
135 | 135 | } |
@@ -139,15 +139,15 @@ discard block |
||
139 | 139 | * |
140 | 140 | * @return int |
141 | 141 | */ |
142 | - final public function getDomain (): int { |
|
142 | + final public function getDomain(): int { |
|
143 | 143 | return $this->getOption(39); // SO_DOMAIN is not exposed by PHP |
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
147 | 147 | * @return int |
148 | 148 | */ |
149 | - final public function getId (): int { |
|
150 | - return (int)$this->resource; |
|
149 | + final public function getId(): int { |
|
150 | + return (int) $this->resource; |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | * @return mixed The option's value. This is never `false`. |
160 | 160 | * @throws SocketError |
161 | 161 | */ |
162 | - public function getOption (int $option) { |
|
162 | + public function getOption(int $option) { |
|
163 | 163 | $value = @socket_get_option($this->resource, SOL_SOCKET, $option); |
164 | 164 | if ($value === false) { |
165 | 165 | throw new SocketError($this->resource, SOCKET_EINVAL); |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | /** |
171 | 171 | * @return resource |
172 | 172 | */ |
173 | - final public function getResource () { |
|
173 | + final public function getResource() { |
|
174 | 174 | return $this->resource; |
175 | 175 | } |
176 | 176 | |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | * @return array `[ 0 => address, 1 => port ]` |
183 | 183 | * @throws SocketError |
184 | 184 | */ |
185 | - public function getSockName (): array { |
|
185 | + public function getSockName(): array { |
|
186 | 186 | if (!@socket_getsockname($this->resource, $addr, $port)) { |
187 | 187 | throw new SocketError($this->resource, SOCKET_EOPNOTSUPP); |
188 | 188 | } |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | /** |
193 | 193 | * @return bool |
194 | 194 | */ |
195 | - public function isOpen (): bool { |
|
195 | + public function isOpen(): bool { |
|
196 | 196 | return is_resource($this->resource); |
197 | 197 | } |
198 | 198 | |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * |
204 | 204 | * @return bool |
205 | 205 | */ |
206 | - final public function isOutOfBand (): bool { |
|
206 | + final public function isOutOfBand(): bool { |
|
207 | 207 | return $this->isReady(self::CH_EXCEPT); |
208 | 208 | } |
209 | 209 | |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | * |
215 | 215 | * @return bool |
216 | 216 | */ |
217 | - final public function isReadable (): bool { |
|
217 | + final public function isReadable(): bool { |
|
218 | 218 | return $this->isReady(self::CH_READ); |
219 | 219 | } |
220 | 220 | |
@@ -228,15 +228,15 @@ discard block |
||
228 | 228 | * @return bool |
229 | 229 | * @throws SocketError |
230 | 230 | */ |
231 | - public function isReady (int $channel, ?float $timeout = 0): bool { |
|
231 | + public function isReady(int $channel, ?float $timeout = 0): bool { |
|
232 | 232 | $rwe = [$channel => [$this->resource]]; |
233 | 233 | // core casts non-null timeout to int. |
234 | 234 | // usec is ignored if timeout is null. |
235 | - $usec = (int)(fmod($timeout, 1) * 1000000); |
|
235 | + $usec = (int) (fmod($timeout, 1) * 1000000); |
|
236 | 236 | if (false === $count = @socket_select($rwe[0], $rwe[1], $rwe[2], $timeout, $usec)) { |
237 | 237 | throw new SocketError($this->resource); |
238 | 238 | } |
239 | - return (bool)$count; |
|
239 | + return (bool) $count; |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | * |
247 | 247 | * @return bool |
248 | 248 | */ |
249 | - final public function isWritable (): bool { |
|
249 | + final public function isWritable(): bool { |
|
250 | 250 | return $this->isReady(self::CH_WRITE); |
251 | 251 | } |
252 | 252 | |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | * @return $this |
271 | 271 | * @throws SocketError |
272 | 272 | */ |
273 | - public function setBlocking (bool $blocking) { |
|
273 | + public function setBlocking(bool $blocking) { |
|
274 | 274 | if ($blocking ? @socket_set_block($this->resource) : @socket_set_nonblock($this->resource)) { |
275 | 275 | return $this; |
276 | 276 | } |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | * @return $this |
288 | 288 | * @throws SocketError |
289 | 289 | */ |
290 | - public function setOption (int $option, $value) { |
|
290 | + public function setOption(int $option, $value) { |
|
291 | 291 | if (!@socket_set_option($this->resource, SOL_SOCKET, $option, $value)) { |
292 | 292 | throw new SocketError($this->resource, SOCKET_EINVAL); |
293 | 293 | } |
@@ -300,10 +300,10 @@ discard block |
||
300 | 300 | * @param float $timeout Zero means "no timeout" (block forever). |
301 | 301 | * @return $this |
302 | 302 | */ |
303 | - public function setTimeout (float $timeout) { |
|
303 | + public function setTimeout(float $timeout) { |
|
304 | 304 | $tv = [ |
305 | - 'sec' => (int)$timeout, |
|
306 | - 'usec' => (int)(fmod($timeout, 1) * 1000000) |
|
305 | + 'sec' => (int) $timeout, |
|
306 | + 'usec' => (int) (fmod($timeout, 1) * 1000000) |
|
307 | 307 | ]; |
308 | 308 | $this->setOption(SO_RCVTIMEO, $tv); |
309 | 309 | $this->setOption(SO_SNDTIMEO, $tv); |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | * @return $this |
334 | 334 | * @throws SocketError |
335 | 335 | */ |
336 | - public function shutdown (int $channel) { |
|
336 | + public function shutdown(int $channel) { |
|
337 | 337 | if (!@socket_shutdown($this->resource, $channel)) { |
338 | 338 | throw new SocketError($this->resource); // reliable errno |
339 | 339 | } |
@@ -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 | } |
@@ -97,7 +97,7 @@ |
||
97 | 97 | /** |
98 | 98 | * Yields all available frames from the peer. |
99 | 99 | * |
100 | - * @return Generator|Frame[] |
|
100 | + * @return Generator |
|
101 | 101 | */ |
102 | 102 | public function getFrames () { |
103 | 103 | $this->buffer .= $this->client->recvAll(); |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | */ |
50 | 50 | protected $maxLength = 10 * 1024 * 1024; |
51 | 51 | |
52 | - public function __construct (WebSocketClient $client) { |
|
52 | + public function __construct(WebSocketClient $client) { |
|
53 | 53 | $this->client = $client; |
54 | 54 | } |
55 | 55 | |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * @return null|Frame |
58 | 58 | * @throws WebSocketError |
59 | 59 | */ |
60 | - protected function getFrame (): ?Frame { |
|
60 | + protected function getFrame(): ?Frame { |
|
61 | 61 | if (!$this->head) { |
62 | 62 | if (preg_match(self::REGEXP, $this->buffer, $head)) { |
63 | 63 | [, $op, $len] = unpack('C2', $head[0]); |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * |
100 | 100 | * @return Generator|Frame[] |
101 | 101 | */ |
102 | - public function getFrames () { |
|
102 | + public function getFrames() { |
|
103 | 103 | $this->buffer .= $this->client->recvAll(); |
104 | 104 | while ($frame = $this->getFrame()) { |
105 | 105 | yield $frame; |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | /** |
110 | 110 | * @return int |
111 | 111 | */ |
112 | - public function getMaxLength (): int { |
|
112 | + public function getMaxLength(): int { |
|
113 | 113 | return $this->maxLength; |
114 | 114 | } |
115 | 115 | |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | * @param int $bytes |
118 | 118 | * @return $this |
119 | 119 | */ |
120 | - public function setMaxLength (int $bytes) { |
|
120 | + public function setMaxLength(int $bytes) { |
|
121 | 121 | if ($bytes < self::MAX_LENGTH_RANGE[0] or $bytes > self::MAX_LENGTH_RANGE[1]) { |
122 | 122 | throw new InvalidArgumentException('Max length must be within range [125,2^63-1]'); |
123 | 123 | } |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | * |
131 | 131 | * @throws WebSocketError |
132 | 132 | */ |
133 | - protected function validate (): void { |
|
133 | + protected function validate(): void { |
|
134 | 134 | if ($this->head['length'] > $this->maxLength) { |
135 | 135 | throw new WebSocketError(Frame::CLOSE_TOO_LARGE, "Payload would exceed {$this->maxLength} bytes"); |
136 | 136 | } |