Base64::urlSafeDecode()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 10
rs 10
c 0
b 0
f 0
cc 2
nc 2
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