Base64::urlSafeEncode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Rogierw\RwAcme\Support;
4
5
class Base64
6
{
7
    public static function urlSafeEncode(string $input): string
8
    {
9
        return str_replace('=', '', strtr(base64_encode($input), '+/', '-_'));
10
    }
11
12
    public static function urlSafeDecode(string $input): string
13
    {
14
        $remainder = strlen($input) % 4;
15
16
        if ($remainder) {
17
            $padlen = 4 - $remainder;
18
            $input .= str_repeat('=', $padlen);
19
        }
20
21
        return base64_decode(strtr($input, '-_', '+/'));
22
    }
23
}
24