| Conditions | 2 |
| Paths | 2 |
| Total Lines | 15 |
| Code Lines | 5 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 4 |
| CRAP Score | 2.032 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 16 | function base64URLEncode(string $string): string |
||
| 17 | { |
||
| 18 | // First of all you should encode $data to Base64 string |
||
| 19 | 1 | $b64 = base64_encode($string); |
|
| 20 | |||
| 21 | // Make sure you get a valid result, otherwise, return FALSE, as the base64_encode() function do |
||
| 22 | 1 | if ($b64 === false) { |
|
| 23 | return false; |
||
|
|
|||
| 24 | } |
||
| 25 | |||
| 26 | // Convert Base64 to Base64URL by replacing “+” with “-” and “/” with “_” |
||
| 27 | 1 | $url = strtr($b64, '+/', '-_'); |
|
| 28 | |||
| 29 | // Remove padding character from the end of line and return the Base64URL result |
||
| 30 | 1 | return rtrim($url, '='); |
|
| 31 | } |
||
| 49 |