@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * @param ReactiveInterface $socket |
23 | 23 | * @return $this |
24 | 24 | */ |
25 | - public function add (ReactiveInterface $socket) { |
|
25 | + public function add(ReactiveInterface $socket) { |
|
26 | 26 | $this->sockets[$socket->getId()] = $socket; |
27 | 27 | return $this; |
28 | 28 | } |
@@ -32,14 +32,14 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @return int |
34 | 34 | */ |
35 | - public function count () { |
|
35 | + public function count() { |
|
36 | 36 | return count($this->sockets); |
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
40 | 40 | * @return SocketInterface[] |
41 | 41 | */ |
42 | - public function getSockets () { |
|
42 | + public function getSockets() { |
|
43 | 43 | return $this->sockets; |
44 | 44 | } |
45 | 45 | |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * @throws Error |
51 | 51 | * @return int Number of sockets that reacted. |
52 | 52 | */ |
53 | - public function react ($timeout = null) { |
|
53 | + public function react($timeout = null) { |
|
54 | 54 | /** @var ReactiveInterface[][] $rwe */ |
55 | 55 | $rwe = [$this->sockets, [], $this->sockets]; |
56 | 56 | $count = AbstractSocket::select($rwe[0], $rwe[1], $rwe[2], $timeout); |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * @param int $id |
70 | 70 | * @return $this |
71 | 71 | */ |
72 | - public function remove ($id) { |
|
72 | + public function remove($id) { |
|
73 | 73 | unset($this->sockets[$id]); |
74 | 74 | return $this; |
75 | 75 | } |
@@ -52,8 +52,7 @@ |
||
52 | 52 | if ($chunk === '') { |
53 | 53 | return $data; |
54 | 54 | } |
55 | - } |
|
56 | - catch (Error $error) { |
|
55 | + } catch (Error $error) { |
|
57 | 56 | $error->setExtra($data); |
58 | 57 | throw $error; |
59 | 58 | } |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | * @return static[] Two instances at indices `0` and `1`. |
18 | 18 | * @throws Error |
19 | 19 | */ |
20 | - public static function newUnixPair (...$extra) { |
|
20 | + public static function newUnixPair(...$extra) { |
|
21 | 21 | if (!@socket_create_pair(AF_UNIX, SOCK_STREAM, 0, $fd)) { |
22 | 22 | throw new Error; // reliable errno |
23 | 23 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @return int |
34 | 34 | */ |
35 | - final public static function getType () { |
|
35 | + final public static function getType() { |
|
36 | 36 | return SOCK_STREAM; |
37 | 37 | } |
38 | 38 | |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * @return string |
47 | 47 | * @throws Error The error's extra data is set to what was partially read. |
48 | 48 | */ |
49 | - public function read ($length) { |
|
49 | + public function read($length) { |
|
50 | 50 | $data = ''; |
51 | 51 | while ($length > 0) { |
52 | 52 | try { |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * @throws Error |
77 | 77 | * @return string |
78 | 78 | */ |
79 | - public function recv ($length, $flags = 0) { |
|
79 | + public function recv($length, $flags = 0) { |
|
80 | 80 | $count = @socket_recv($this->resource, $data, $length, $flags); |
81 | 81 | if ($count === false) { |
82 | 82 | $error = new Error($this->resource, SOCKET_EINVAL); |
@@ -96,11 +96,9 @@ discard block |
||
96 | 96 | public function __construct ($resource) { |
97 | 97 | if (!is_resource($resource) or get_resource_type($resource) !== 'Socket') { |
98 | 98 | throw new InvalidArgumentException('Expected an open socket resource.', SOCKET_EBADF); |
99 | - } |
|
100 | - elseif (socket_get_option($resource, SOL_SOCKET, SO_TYPE) !== static::getType()) { |
|
99 | + } elseif (socket_get_option($resource, SOL_SOCKET, SO_TYPE) !== static::getType()) { |
|
101 | 100 | throw new InvalidArgumentException('The given socket resource is of the wrong type for ' . get_class(), SOCKET_ESOCKTNOSUPPORT); |
102 | - } |
|
103 | - elseif ($errno = Error::getLast($resource)) { |
|
101 | + } elseif ($errno = Error::getLast($resource)) { |
|
104 | 102 | $error = new Error(SOCKET_EBADFD); |
105 | 103 | $error->setExtra($errno); |
106 | 104 | throw $error; |
@@ -331,8 +329,7 @@ discard block |
||
331 | 329 | public function setBlocking ($blocking) { |
332 | 330 | if ($blocking) { |
333 | 331 | $success = @socket_set_block($this->resource); |
334 | - } |
|
335 | - else { |
|
332 | + } else { |
|
336 | 333 | $success = @socket_set_nonblock($this->resource); |
337 | 334 | } |
338 | 335 | if (!$success) { |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * @return static |
42 | 42 | * @throws Error |
43 | 43 | */ |
44 | - public static function create ($domain = AF_INET, ...$extra) { |
|
44 | + public static function create($domain = AF_INET, ...$extra) { |
|
45 | 45 | if (!$resource = @socket_create($domain, static::getType(), 0)) { // auto-protocol |
46 | 46 | throw new Error; // reliable errno |
47 | 47 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * @return int |
61 | 61 | * @throws Error |
62 | 62 | */ |
63 | - public static function select (array &$read, array &$write, array &$except, $timeout = null) { |
|
63 | + public static function select(array &$read, array &$write, array &$except, $timeout = null) { |
|
64 | 64 | $getResource = function(SocketInterface $socket) { |
65 | 65 | return $socket->getResource(); |
66 | 66 | }; |
@@ -90,12 +90,12 @@ discard block |
||
90 | 90 | * @throws Error (`SOCKET_EBADFD`) There was a pending error on the socket. |
91 | 91 | * The preexisting error code is set as the exception's extra data. |
92 | 92 | */ |
93 | - public function __construct ($resource) { |
|
93 | + public function __construct($resource) { |
|
94 | 94 | if (!is_resource($resource) or get_resource_type($resource) !== 'Socket') { |
95 | 95 | throw new InvalidArgumentException('Expected an open socket resource.', SOCKET_EBADF); |
96 | 96 | } |
97 | 97 | elseif (socket_get_option($resource, SOL_SOCKET, SO_TYPE) !== static::getType()) { |
98 | - throw new InvalidArgumentException('The given socket resource is of the wrong type for ' . get_class(), SOCKET_ESOCKTNOSUPPORT); |
|
98 | + throw new InvalidArgumentException('The given socket resource is of the wrong type for '.get_class(), SOCKET_ESOCKTNOSUPPORT); |
|
99 | 99 | } |
100 | 100 | elseif ($errno = Error::getLast($resource)) { |
101 | 101 | $error = new Error(SOCKET_EBADFD); |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | /** |
111 | 111 | * Closes the socket if it's open. |
112 | 112 | */ |
113 | - public function __destruct () { |
|
113 | + public function __destruct() { |
|
114 | 114 | $this->close(); |
115 | 115 | } |
116 | 116 | |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * @return $this |
126 | 126 | * @throws Error |
127 | 127 | */ |
128 | - public function await ($channel) { |
|
128 | + public function await($channel) { |
|
129 | 129 | $select = [$channel => [$this->resource]]; |
130 | 130 | $count = @socket_select($select[self::CH_READ], $select[self::CH_WRITE], $select[self::CH_EXCEPT], null); |
131 | 131 | if (!$count) { |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * |
145 | 145 | * @return $this |
146 | 146 | */ |
147 | - public function close () { |
|
147 | + public function close() { |
|
148 | 148 | // socket_close() never errors, but we guard anyway to prevent |
149 | 149 | // a redundant call to onClose(), and an incorrect call to it if |
150 | 150 | // the constructor failed and the destructor is calling this. |
@@ -158,14 +158,14 @@ discard block |
||
158 | 158 | /** |
159 | 159 | * @return int |
160 | 160 | */ |
161 | - final public function getDomain () { |
|
161 | + final public function getDomain() { |
|
162 | 162 | return $this->domain; |
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
166 | 166 | * @return int |
167 | 167 | */ |
168 | - final public function getId () { |
|
168 | + final public function getId() { |
|
169 | 169 | return (int)$this->resource; |
170 | 170 | } |
171 | 171 | |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * @throws Error |
179 | 179 | * @return mixed The option's value. This is never `false`. |
180 | 180 | */ |
181 | - public function getOption ($option) { |
|
181 | + public function getOption($option) { |
|
182 | 182 | $value = @socket_get_option($this->resource, SOL_SOCKET, $option); |
183 | 183 | if ($value === false) { |
184 | 184 | throw new Error($this->resource, SOCKET_EINVAL); |
@@ -189,14 +189,14 @@ discard block |
||
189 | 189 | /** |
190 | 190 | * @return int |
191 | 191 | */ |
192 | - final public function getProtocol () { |
|
192 | + final public function getProtocol() { |
|
193 | 193 | return $this->protocol; |
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
197 | 197 | * @return resource |
198 | 198 | */ |
199 | - final public function getResource () { |
|
199 | + final public function getResource() { |
|
200 | 200 | return $this->resource; |
201 | 201 | } |
202 | 202 | |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | * @throws Error |
209 | 209 | * @return array String address/file and integer port at indices `0` and `1`. |
210 | 210 | */ |
211 | - public function getSockName () { |
|
211 | + public function getSockName() { |
|
212 | 212 | if (!@socket_getsockname($this->resource, $addr, $port)) { |
213 | 213 | throw new Error($this->resource, SOCKET_EOPNOTSUPP); |
214 | 214 | } |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | * |
221 | 221 | * @return bool |
222 | 222 | */ |
223 | - public function isOpen () { |
|
223 | + public function isOpen() { |
|
224 | 224 | return is_resource($this->resource); |
225 | 225 | } |
226 | 226 | |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | * @return bool |
233 | 233 | * @throws Error |
234 | 234 | */ |
235 | - public function isOutOfBand () { |
|
235 | + public function isOutOfBand() { |
|
236 | 236 | return $this->isReady(self::CH_EXCEPT); |
237 | 237 | } |
238 | 238 | |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | * @return bool |
245 | 245 | * @throws Error |
246 | 246 | */ |
247 | - final public function isReadable () { |
|
247 | + final public function isReadable() { |
|
248 | 248 | return $this->isReady(self::CH_READ); |
249 | 249 | } |
250 | 250 | |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | * @return bool |
259 | 259 | * @throws Error |
260 | 260 | */ |
261 | - public function isReady ($channel, $timeout = 0.0) { |
|
261 | + public function isReady($channel, $timeout = 0.0) { |
|
262 | 262 | $usec = (int)(fmod($timeout, 1) * 1000000); // ignored if timeout is null |
263 | 263 | $select = [$channel => [$this->resource]]; |
264 | 264 | $count = $count = @socket_select( |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | * @return bool |
283 | 283 | * @throws Error |
284 | 284 | */ |
285 | - final public function isWritable () { |
|
285 | + final public function isWritable() { |
|
286 | 286 | return $this->isReady(self::CH_WRITE); |
287 | 287 | } |
288 | 288 | |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | * |
292 | 292 | * @return void |
293 | 293 | */ |
294 | - protected function onClose () { |
|
294 | + protected function onClose() { |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | /** |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | * @param int $channel `SocketInterface` channel constant. |
301 | 301 | * @return void |
302 | 302 | */ |
303 | - protected function onShutdown ($channel) { |
|
303 | + protected function onShutdown($channel) { |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | /** |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | * |
309 | 309 | * @return void |
310 | 310 | */ |
311 | - protected function onTimeout () { |
|
311 | + protected function onTimeout() { |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | /** |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | * @throws Error |
330 | 330 | * @return $this |
331 | 331 | */ |
332 | - public function setBlocking ($blocking) { |
|
332 | + public function setBlocking($blocking) { |
|
333 | 333 | if ($blocking) { |
334 | 334 | $success = @socket_set_block($this->resource); |
335 | 335 | } |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | * @throws Error |
353 | 353 | * @return $this |
354 | 354 | */ |
355 | - public function setOption ($option, $value) { |
|
355 | + public function setOption($option, $value) { |
|
356 | 356 | if (!@socket_set_option($this->resource, SOL_SOCKET, $option, $value)) { |
357 | 357 | throw new Error($this->resource, SOCKET_EINVAL); |
358 | 358 | } |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | * @return $this |
367 | 367 | * @throws Error |
368 | 368 | */ |
369 | - public function setTimeout ($timeout) { |
|
369 | + public function setTimeout($timeout) { |
|
370 | 370 | $timeval = ['sec' => (int)$timeout, 'usec' => (int)(fmod($timeout, 1) * 1000000)]; |
371 | 371 | $this->setOption(SO_RCVTIMEO, $timeval); |
372 | 372 | $this->setOption(SO_SNDTIMEO, $timeval); |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | * @throws Error |
394 | 394 | * @return $this |
395 | 395 | */ |
396 | - public function shutdown ($channel) { |
|
396 | + public function shutdown($channel) { |
|
397 | 397 | $this->onShutdown($channel); |
398 | 398 | if (!@socket_shutdown($this->resource, $channel)) { |
399 | 399 | throw new Error($this->resource); // reliable errno |
@@ -57,14 +57,12 @@ |
||
57 | 57 | public function __construct ($subject = null, $fallback = 0) { |
58 | 58 | if (is_int($subject)) { |
59 | 59 | $errno = $subject; |
60 | - } |
|
61 | - else { |
|
60 | + } else { |
|
62 | 61 | $errno = static::getLast($subject); |
63 | 62 | } |
64 | 63 | if ($errno) { |
65 | 64 | $message = socket_strerror($errno); |
66 | - } |
|
67 | - else { |
|
65 | + } else { |
|
68 | 66 | $errno = $fallback; |
69 | 67 | $message = error_get_last()['message']; |
70 | 68 | } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | * @param resource $resource PHP socket resource, or `null` for the global error. |
28 | 28 | * @return int If the resource is closed or not a socket, `SOCKET_EBADF` is returned. |
29 | 29 | */ |
30 | - public static function getLast ($resource = null) { |
|
30 | + public static function getLast($resource = null) { |
|
31 | 31 | if (isset($resource)) { |
32 | 32 | if (@get_resource_type($resource) !== 'Socket') { |
33 | 33 | return SOCKET_EBADF; |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * PHP's last suppressed warning is used for the message. |
54 | 54 | * |
55 | 55 | */ |
56 | - public function __construct ($subject = null, $fallback = 0) { |
|
56 | + public function __construct($subject = null, $fallback = 0) { |
|
57 | 57 | if (is_int($subject)) { |
58 | 58 | $errno = $subject; |
59 | 59 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | /** |
74 | 74 | * @return mixed |
75 | 75 | */ |
76 | - public function getExtra () { |
|
76 | + public function getExtra() { |
|
77 | 77 | return $this->extra; |
78 | 78 | } |
79 | 79 | |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | * @param mixed $extra |
82 | 82 | * @return $this |
83 | 83 | */ |
84 | - public function setExtra ($extra) { |
|
84 | + public function setExtra($extra) { |
|
85 | 85 | $this->extra = $extra; |
86 | 86 | return $this; |
87 | 87 | } |
@@ -17,8 +17,7 @@ |
||
17 | 17 | public function __toString () { |
18 | 18 | try { |
19 | 19 | return implode(':', $this->getSockName()); |
20 | - } |
|
21 | - catch (\Exception $exception) { |
|
20 | + } catch (\Exception $exception) { |
|
22 | 21 | return ':'; |
23 | 22 | } |
24 | 23 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | * |
15 | 15 | * @return string |
16 | 16 | */ |
17 | - public function __toString () { |
|
17 | + public function __toString() { |
|
18 | 18 | try { |
19 | 19 | return implode(':', $this->getSockName()); |
20 | 20 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * @throws Error |
37 | 37 | * @return $this |
38 | 38 | */ |
39 | - public function bind (string $address, int $port = 0) { |
|
39 | + public function bind(string $address, int $port = 0) { |
|
40 | 40 | if (!@socket_bind($this->resource, $address, $port)) { |
41 | 41 | throw new Error($this->resource, SOCKET_EOPNOTSUPP); |
42 | 42 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | * |
15 | 15 | * @return string |
16 | 16 | */ |
17 | - public function __toString () { |
|
17 | + public function __toString() { |
|
18 | 18 | try { |
19 | 19 | return implode(':', $this->getPeerName()); |
20 | 20 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * @throws Error |
39 | 39 | * @return $this |
40 | 40 | */ |
41 | - public function connect ($address, $port = 0) { |
|
41 | + public function connect($address, $port = 0) { |
|
42 | 42 | if (!@socket_connect($this->resource, $address, $port)) { |
43 | 43 | // ignore expected errors for non-blocking connections |
44 | 44 | $errno = Error::getLast($this->resource); |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * @throws Error |
59 | 59 | * @return array Address and port at indices `0` and `1`. |
60 | 60 | */ |
61 | - public function getPeerName () { |
|
61 | + public function getPeerName() { |
|
62 | 62 | if ($this->domain === AF_UNIX) { |
63 | 63 | return [$this->getOption(self::SO_PEERCRED), 0]; |
64 | 64 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * @throws Error |
81 | 81 | * @return int Total bytes sent. |
82 | 82 | */ |
83 | - public function send ($data, $flags = 0) { |
|
83 | + public function send($data, $flags = 0) { |
|
84 | 84 | $count = @socket_send($this->resource, $data, PHP_INT_MAX, $flags); |
85 | 85 | if ($count === false) { |
86 | 86 | $error = new Error($this->resource); // reliable errno |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * @throws Error Total bytes sent is set as the error's extra data. |
100 | 100 | * @return $this |
101 | 101 | */ |
102 | - public function write ($data) { |
|
102 | + public function write($data) { |
|
103 | 103 | $data = (string)$data; |
104 | 104 | $length = strlen($data); |
105 | 105 | $total = 0; |
@@ -19,8 +19,7 @@ discard block |
||
19 | 19 | public function __toString () { |
20 | 20 | try { |
21 | 21 | return implode(':', $this->getPeerName()); |
22 | - } |
|
23 | - catch (Exception $exception) { |
|
22 | + } catch (Exception $exception) { |
|
24 | 23 | return ':'; |
25 | 24 | } |
26 | 25 | } |
@@ -109,8 +108,7 @@ discard block |
||
109 | 108 | try { |
110 | 109 | $total += $count = $this->await(self::CH_WRITE)->send($data); |
111 | 110 | $data = substr($data, $count); // 0 bytes sent = unaltered buffer |
112 | - } |
|
113 | - catch (Error $error) { |
|
111 | + } catch (Error $error) { |
|
114 | 112 | $error->setExtra($total); |
115 | 113 | throw $error; |
116 | 114 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * |
13 | 13 | * @return int |
14 | 14 | */ |
15 | - final public static function getType () { |
|
15 | + final public static function getType() { |
|
16 | 16 | return SOCK_DGRAM; |
17 | 17 | } |
18 | 18 | |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * @throws Error |
31 | 31 | * @return string |
32 | 32 | */ |
33 | - public function recv ($length, $flags = 0, &$name = null, &$port = 0) { |
|
33 | + public function recv($length, $flags = 0, &$name = null, &$port = 0) { |
|
34 | 34 | $count = @socket_recvfrom($this->resource, $data, $length, $flags, $name, $port); |
35 | 35 | if ($count === false) { |
36 | 36 | $error = new Error($this->resource, SOCKET_EOPNOTSUPP); |
@@ -12,7 +12,7 @@ |
||
12 | 12 | * |
13 | 13 | * @return int |
14 | 14 | */ |
15 | - final public static function getType () { |
|
15 | + final public static function getType() { |
|
16 | 16 | return SOCK_DGRAM; |
17 | 17 | } |
18 | 18 |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * @param bool $final |
26 | 26 | * @return string |
27 | 27 | */ |
28 | - public static function pack (string $payload, int $opCode = self::OP_TEXT, bool $final = true): string { |
|
28 | + public static function pack(string $payload, int $opCode = self::OP_TEXT, bool $final = true): string { |
|
29 | 29 | $frame = chr(0x80 | $opCode); |
30 | 30 | $len = strlen($payload); |
31 | 31 | if ($len > 65535) { |
@@ -39,14 +39,14 @@ discard block |
||
39 | 39 | else { |
40 | 40 | $frame .= chr($len); |
41 | 41 | } |
42 | - return $frame . $payload; |
|
42 | + return $frame.$payload; |
|
43 | 43 | } |
44 | 44 | |
45 | - public function __construct (string $data) { |
|
45 | + public function __construct(string $data) { |
|
46 | 46 | $this->data = $data; |
47 | 47 | } |
48 | 48 | |
49 | - final public function getLength () { |
|
49 | + final public function getLength() { |
|
50 | 50 | switch ($char = ord($this->data[1]) & 0x7f) { |
51 | 51 | case 127: // big-endian long-long |
52 | 52 | return unpack('J', substr($this->data, 2, 8)); |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | /** |
61 | 61 | * @return int[] |
62 | 62 | */ |
63 | - final public function getMask () { |
|
63 | + final public function getMask() { |
|
64 | 64 | if ($this->isMasked()) { |
65 | 65 | switch (ord($this->data[1]) & 0x7f) { |
66 | 66 | case 127: |
@@ -74,11 +74,11 @@ discard block |
||
74 | 74 | return [0, 0, 0, 0]; |
75 | 75 | } |
76 | 76 | |
77 | - final public function getOpCode (): int { |
|
77 | + final public function getOpCode(): int { |
|
78 | 78 | return ord($this->data[0]) & 0x0f; |
79 | 79 | } |
80 | 80 | |
81 | - final public function getPayload (): string { |
|
81 | + final public function getPayload(): string { |
|
82 | 82 | $length = $this->getLength(); |
83 | 83 | if ($length === 0) { |
84 | 84 | return ''; |
@@ -102,27 +102,27 @@ discard block |
||
102 | 102 | return $decoded; |
103 | 103 | } |
104 | 104 | |
105 | - final public function isBinary (): bool { |
|
105 | + final public function isBinary(): bool { |
|
106 | 106 | return $this->getOpCode() === self::OP_BINARY; |
107 | 107 | } |
108 | 108 | |
109 | - final public function isClose (): bool { |
|
109 | + final public function isClose(): bool { |
|
110 | 110 | return $this->getOpCode() === self::OP_CLOSE; |
111 | 111 | } |
112 | 112 | |
113 | - final public function isFinal (): bool { |
|
113 | + final public function isFinal(): bool { |
|
114 | 114 | return (bool)(ord($this->data[0]) & 0x80); |
115 | 115 | } |
116 | 116 | |
117 | - final public function isMasked (): bool { |
|
117 | + final public function isMasked(): bool { |
|
118 | 118 | return (bool)(ord($this->data[1]) & 0x80); |
119 | 119 | } |
120 | 120 | |
121 | - final public function isPong (): bool { |
|
121 | + final public function isPong(): bool { |
|
122 | 122 | return $this->getOpCode() === self::OP_PONG; |
123 | 123 | } |
124 | 124 | |
125 | - final public function isText (): bool { |
|
125 | + final public function isText(): bool { |
|
126 | 126 | return $this->getOpCode() === self::OP_TEXT; |
127 | 127 | } |
128 | 128 |
@@ -31,12 +31,10 @@ |
||
31 | 31 | if ($len > 65535) { |
32 | 32 | $frame .= chr(127); |
33 | 33 | $frame .= pack('J', $len); |
34 | - } |
|
35 | - elseif ($len >= 126) { |
|
34 | + } elseif ($len >= 126) { |
|
36 | 35 | $frame .= chr(126); |
37 | 36 | $frame .= pack('n', $len); |
38 | - } |
|
39 | - else { |
|
37 | + } else { |
|
40 | 38 | $frame .= chr($len); |
41 | 39 | } |
42 | 40 | return $frame . $payload; |