@@ -107,8 +107,8 @@ discard block |
||
107 | 107 | |
108 | 108 | $result->setStatusCode(curl_getinfo($CurlHandle, CURLINFO_HTTP_CODE)); |
109 | 109 | $result->setHeaderSize(curl_getinfo($CurlHandle, CURLINFO_HEADER_SIZE)); |
110 | - $result->setHeaders(substr((string)$response, 0, $result->getHeaderSize())); |
|
111 | - $result->setBody(substr((string)$response, $result->getHeaderSize())); |
|
110 | + $result->setHeaders(substr((string) $response, 0, $result->getHeaderSize())); |
|
111 | + $result->setBody(substr((string) $response, $result->getHeaderSize())); |
|
112 | 112 | |
113 | 113 | curl_close($CurlHandle); |
114 | 114 | |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | ] |
327 | 327 | ]); |
328 | 328 | |
329 | - return (int)$response->getHeaderLine('Content-Length') ?? 0; |
|
329 | + return (int) $response->getHeaderLine('Content-Length') ?? 0; |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | /** |
@@ -100,7 +100,7 @@ |
||
100 | 100 | curl_setopt($cHandler, CURLOPT_TIMEOUT, $options->getTimeout()); |
101 | 101 | |
102 | 102 | # If self-signed certs are allowed, set it. |
103 | - if ((bool)getenv('HAS_SELF_SIGNED_CERT') === true) { |
|
103 | + if ((bool) getenv('HAS_SELF_SIGNED_CERT') === true) { |
|
104 | 104 | curl_setopt($cHandler, CURLOPT_SSL_VERIFYPEER, false); |
105 | 105 | curl_setopt($cHandler, CURLOPT_SSL_VERIFYHOST, false); |
106 | 106 | } |
@@ -9,13 +9,13 @@ discard block |
||
9 | 9 | $close_time = time() + 10; |
10 | 10 | $SocketClient = new WebSocket(); |
11 | 11 | |
12 | -$SocketClient->onWhile = function (WebSocket $socket) use ($close_time) { |
|
12 | +$SocketClient->onWhile = function(WebSocket $socket) use ($close_time) { |
|
13 | 13 | if (time() >= $close_time) { |
14 | 14 | $socket->close(); |
15 | 15 | } |
16 | 16 | }; |
17 | 17 | |
18 | -$SocketClient->onOpen = function (WebSocket $socket) { |
|
18 | +$SocketClient->onOpen = function(WebSocket $socket) { |
|
19 | 19 | echo sprintf( |
20 | 20 | '<pre><b>%s</b>: Connected to %s</pre><br/>', |
21 | 21 | date('Y-m-d H:i:s'), |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | ])); |
33 | 33 | }; |
34 | 34 | |
35 | -$SocketClient->onClose = function (WebSocket $socket, int $closeStatus) { |
|
35 | +$SocketClient->onClose = function(WebSocket $socket, int $closeStatus) { |
|
36 | 36 | echo sprintf( |
37 | 37 | '<pre><b>%s</b>: Disconnected with status: %s</pre><br/>', |
38 | 38 | date('Y-m-d H:i:s'), |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | ); |
41 | 41 | }; |
42 | 42 | |
43 | -$SocketClient->onMessage = function (WebSocket $socket, string $message) { |
|
43 | +$SocketClient->onMessage = function(WebSocket $socket, string $message) { |
|
44 | 44 | $data = json_decode($message, true); |
45 | 45 | if (isset($data['id']) && $data['id'] == "price") { |
46 | 46 | echo sprintf( |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | } |
52 | 52 | }; |
53 | 53 | |
54 | -$SocketClient->onError = function (WebSocket $socket, WebSocketException $exception) { |
|
54 | +$SocketClient->onError = function(WebSocket $socket, WebSocketException $exception) { |
|
55 | 55 | echo sprintf( |
56 | 56 | "<pre>%s: Error: %s<br>File: %s:%s<br></pre><br>", |
57 | 57 | date('Y-m-d H:i:s'), |
@@ -3,17 +3,17 @@ |
||
3 | 3 | |
4 | 4 | $SocketClient = new \EasyHttp\WebSocket(); |
5 | 5 | |
6 | -$SocketClient->onOpen = function (\EasyHttp\WebSocket $socket) { |
|
6 | +$SocketClient->onOpen = function(\EasyHttp\WebSocket $socket) { |
|
7 | 7 | echo "Connected to server<br>"; |
8 | 8 | $socket->send("Hello World"); |
9 | 9 | }; |
10 | 10 | |
11 | -$SocketClient->onMessage = function (\EasyHttp\WebSocket $socket, $message) { |
|
11 | +$SocketClient->onMessage = function(\EasyHttp\WebSocket $socket, $message) { |
|
12 | 12 | echo $message . "<br>"; |
13 | 13 | $socket->close(); |
14 | 14 | }; |
15 | 15 | |
16 | -$SocketClient->onClose = function (\EasyHttp\WebSocket $socket, int $closeStatus) { |
|
16 | +$SocketClient->onClose = function(\EasyHttp\WebSocket $socket, int $closeStatus) { |
|
17 | 17 | echo "Disconnected with status: $closeStatus<br>"; |
18 | 18 | }; |
19 | 19 |
@@ -114,19 +114,19 @@ discard block |
||
114 | 114 | { |
115 | 115 | if ($client instanceof SocketClient) { |
116 | 116 | |
117 | - $this->onOpen = function ($socket) use ($client) { |
|
117 | + $this->onOpen = function($socket) use ($client) { |
|
118 | 118 | $client->onOpen($socket); |
119 | 119 | }; |
120 | 120 | |
121 | - $this->onClose = function ($socket, int $closeStatus) use ($client) { |
|
121 | + $this->onClose = function($socket, int $closeStatus) use ($client) { |
|
122 | 122 | $client->onClose($socket, $closeStatus); |
123 | 123 | }; |
124 | 124 | |
125 | - $this->onError = function ($socket, WebSocketException $exception) use ($client) { |
|
125 | + $this->onError = function($socket, WebSocketException $exception) use ($client) { |
|
126 | 126 | $client->onError($socket, $exception); |
127 | 127 | }; |
128 | 128 | |
129 | - $this->onMessage = function ($socket, string $message) use ($client) { |
|
129 | + $this->onMessage = function($socket, string $message) use ($client) { |
|
130 | 130 | $client->onMessage($socket, $message); |
131 | 131 | }; |
132 | 132 | } |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | . implode( |
347 | 347 | "\r\n", |
348 | 348 | array_map( |
349 | - function ($key, $value) { |
|
349 | + function($key, $value) { |
|
350 | 350 | return "$key: $value"; |
351 | 351 | }, |
352 | 352 | array_keys($headers), |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | */ |
73 | 73 | private function getPayloadLength(string $data): float|int |
74 | 74 | { |
75 | - $payloadLength = (int)ord($data[1]) & self::MASK_127; // Bits 1-7 in byte 1 |
|
75 | + $payloadLength = (int) ord($data[1]) & self::MASK_127; // Bits 1-7 in byte 1 |
|
76 | 76 | if ($payloadLength > self::MASK_125) { |
77 | 77 | if ($payloadLength === self::MASK_126) { |
78 | 78 | $data = $this->read(2); // 126: Payload is a 16-bit unsigned int |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | private function getPayloadData(string $data, int $payloadLength): string |
95 | 95 | { |
96 | 96 | // Masking? |
97 | - $mask = (bool)(ord($data[1]) >> 7); // Bit 0 in byte 1 |
|
97 | + $mask = (bool) (ord($data[1]) >> 7); // Bit 0 in byte 1 |
|
98 | 98 | $payload = ''; |
99 | 99 | $maskingKey = ''; |
100 | 100 | |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | if ($mask) { |
111 | 111 | // Unmask payload. |
112 | 112 | for ($i = 0; $i < $payloadLength; $i++) { |
113 | - $payload .= ($data[$i] ^ $maskingKey[$i % 4]); |
|
113 | + $payload .= ($data[$i]^$maskingKey[$i % 4]); |
|
114 | 114 | } |
115 | 115 | } else { |
116 | 116 | $payload = $data; |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | return null; |
132 | 132 | } |
133 | 133 | |
134 | - $final = (bool)(ord($data[0]) & 1 << 7); |
|
134 | + $final = (bool) (ord($data[0]) & 1 << 7); |
|
135 | 135 | |
136 | 136 | $opcodeInt = ord($data[0]) & 31; |
137 | 137 | $opcodeInts = array_flip(self::$opcodes); |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | // Binary string for header. |
199 | 199 | $frameHeadBin = ''; |
200 | 200 | // Write FIN, final fragment bit. |
201 | - $frameHeadBin .= (bool)$final ? '1' : '0'; |
|
201 | + $frameHeadBin .= (bool) $final ? '1' : '0'; |
|
202 | 202 | // RSV 1, 2, & 3 false and unused. |
203 | 203 | $frameHeadBin .= '000'; |
204 | 204 | // Opcode rest of the byte. |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | |
237 | 237 | // Append payload to frame: |
238 | 238 | for ($i = 0; $i < $payloadLen; $i++) { |
239 | - $frame .= ($masked === true) ? $payload[$i] ^ $mask[$i % 4] : $payload[$i]; |
|
239 | + $frame .= ($masked === true) ? $payload[$i]^$mask[$i % 4] : $payload[$i]; |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | $this->write($frame); |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | */ |
94 | 94 | public static function insensitiveString(string $string, string $value): bool |
95 | 95 | { |
96 | - return (bool)preg_match_all('/' . $value . '/i', $string); |
|
96 | + return (bool) preg_match_all('/' . $value . '/i', $string); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | */ |
115 | 115 | public static function time(): int |
116 | 116 | { |
117 | - return (int)(microtime(true) * 1000); |
|
117 | + return (int) (microtime(true) * 1000); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |