@@ -69,11 +69,15 @@ |
||
| 69 | 69 | { |
| 70 | 70 | if ($binaryPrefix) { |
| 71 | 71 | $unit = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB'); |
| 72 | - if ($bytes == 0) return '0 ' . $unit[0]; |
|
| 72 | + if ($bytes == 0) { |
|
| 73 | + return '0 ' . $unit[0]; |
|
| 74 | + } |
|
| 73 | 75 | return @round($bytes / pow(1024, ($i = floor(log($bytes, 1024)))), 2) . ' ' . ($unit[$i] ?? 'B'); |
| 74 | 76 | } else { |
| 75 | 77 | $unit = array('B', 'KB', 'MB', 'GB', 'TB', 'PB'); |
| 76 | - if ($bytes == 0) return '0 ' . $unit[0]; |
|
| 78 | + if ($bytes == 0) { |
|
| 79 | + return '0 ' . $unit[0]; |
|
| 80 | + } |
|
| 77 | 81 | return @round($bytes / pow(1000, ($i = floor(log($bytes, 1000)))), 2) . ' ' . ($unit[$i] ?? 'B'); |
| 78 | 82 | } |
| 79 | 83 | } |
@@ -132,7 +132,9 @@ |
||
| 132 | 132 | public function save(string $filePath): bool |
| 133 | 133 | { |
| 134 | 134 | $pathInfo = pathinfo($filePath, PATHINFO_DIRNAME); |
| 135 | - if (gettype($pathInfo) != "string") $pathInfo = $pathInfo['dirname']; |
|
| 135 | + if (gettype($pathInfo) != "string") { |
|
| 136 | + $pathInfo = $pathInfo['dirname']; |
|
| 137 | + } |
|
| 136 | 138 | if (!file_exists($pathInfo)) { |
| 137 | 139 | throw new \InvalidArgumentException('The directory does not exist'); |
| 138 | 140 | } |
@@ -54,7 +54,9 @@ |
||
| 54 | 54 | */ |
| 55 | 55 | public function getInfoFromCurl(): CurlInfo|false |
| 56 | 56 | { |
| 57 | - if (empty($this->getCurlHandle())) return false; |
|
| 57 | + if (empty($this->getCurlHandle())) { |
|
| 58 | + return false; |
|
| 59 | + } |
|
| 58 | 60 | return new CurlInfo(curl_getinfo($this->curlHandle)); |
| 59 | 61 | } |
| 60 | 62 | |
@@ -99,9 +99,11 @@ discard block |
||
| 99 | 99 | public function request(string $method, string $uri, array|HttpOptions $options = []): HttpResponse |
| 100 | 100 | { |
| 101 | 101 | $CurlHandle = $this->create_curl_handler($method, $uri, $options); |
| 102 | - if (!$CurlHandle) throw new RuntimeException( |
|
| 102 | + if (!$CurlHandle) { |
|
| 103 | + throw new RuntimeException( |
|
| 103 | 104 | 'An error occurred while creating the curl handler' |
| 104 | 105 | ); |
| 106 | + } |
|
| 105 | 107 | |
| 106 | 108 | $result = new HttpResponse(); |
| 107 | 109 | $result->setCurlHandle($CurlHandle); |
@@ -145,9 +147,11 @@ discard block |
||
| 145 | 147 | $request['uri'], |
| 146 | 148 | $request['options'] ?? [] |
| 147 | 149 | ); |
| 148 | - if (!$CurlHandle) throw new RuntimeException( |
|
| 150 | + if (!$CurlHandle) { |
|
| 151 | + throw new RuntimeException( |
|
| 149 | 152 | 'An error occurred while creating the curl handler' |
| 150 | 153 | ); |
| 154 | + } |
|
| 151 | 155 | $handlers[] = $CurlHandle; |
| 152 | 156 | curl_multi_add_handle($multi_handler, $CurlHandle); |
| 153 | 157 | |
@@ -207,14 +211,18 @@ discard block |
||
| 207 | 211 | private function create_curl_handler(?string $method, string $uri, array|HttpOptions $options = []): false|CurlHandle |
| 208 | 212 | { |
| 209 | 213 | $handler = curl_init(); |
| 210 | - if (is_resource($handler) || !$handler) return false; |
|
| 214 | + if (is_resource($handler) || !$handler) { |
|
| 215 | + return false; |
|
| 216 | + } |
|
| 211 | 217 | |
| 212 | 218 | if (gettype($options) === 'array') { |
| 213 | 219 | $options = new HttpOptions($options); |
| 214 | 220 | } |
| 215 | 221 | |
| 216 | 222 | if (count($options->getQuery()) > 0) { |
| 217 | - if (!str_contains($uri, '?')) $uri .= '?'; |
|
| 223 | + if (!str_contains($uri, '?')) { |
|
| 224 | + $uri .= '?'; |
|
| 225 | + } |
|
| 218 | 226 | $uri .= $options->getQueryString(); |
| 219 | 227 | } |
| 220 | 228 | |
@@ -413,7 +421,9 @@ discard block |
||
| 413 | 421 | |
| 414 | 422 | $headers = []; |
| 415 | 423 | foreach ($options->getHeader() as $header => $value) { |
| 416 | - if (Utils::insensitiveString($header, 'content-type')) continue; |
|
| 424 | + if (Utils::insensitiveString($header, 'content-type')) { |
|
| 425 | + continue; |
|
| 426 | + } |
|
| 417 | 427 | $headers[] = $header . ': ' . $value; |
| 418 | 428 | } |
| 419 | 429 | $headers[] = 'Content-Type: multipart/form-data'; |