| Total Complexity | 6 |
| Total Lines | 55 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | class Helpers |
||
| 13 | { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Encode a JSON string to a base64 Url string |
||
| 17 | * |
||
| 18 | * @param string $jsonTokenString |
||
| 19 | * |
||
| 20 | * @return string |
||
| 21 | */ |
||
| 22 | public static function encode(string $jsonTokenString): string |
||
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Decode a base64 Url string to a JSON string |
||
| 29 | * |
||
| 30 | * @param string $base64UrlString |
||
| 31 | * |
||
| 32 | * @return string |
||
| 33 | */ |
||
| 34 | public static function decode(string $base64UrlString): string |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @param int $code |
||
| 46 | * @param $data |
||
| 47 | */ |
||
| 48 | public static function returnResponse(int $code, $data): void |
||
| 49 | { |
||
| 50 | header('Content-Type: application/json; charset=utf-8'); |
||
| 51 | http_response_code($code); |
||
| 52 | die(json_encode(['response' => ['status' => $code, 'result' => $data]])); |
||
|
|
|||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @param int $code |
||
| 57 | * @param null|string $message |
||
| 58 | */ |
||
| 59 | public static function throwError(int $code, ?string $message = null): void |
||
| 67 | ], |
||
| 68 | ])); |
||
| 72 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.