Base64UrlEncoding::encode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace MadWizard\WebAuthn\Format;
4
5
use MadWizard\WebAuthn\Exception\ParseException;
6
use function base64_decode;
7
use function base64_encode;
8
9
final class Base64UrlEncoding
10
{
11 34
    public static function encode(string $data): string
12
    {
13 34
        return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
14
    }
15
16 66
    public static function decode(string $data): string
17
    {
18 66
        $res = base64_decode(strtr($data, '-_', '+/'), true);
19 66
        if ($res === false) {
20 2
            throw new ParseException('Failed to decode base64url encoded data');
21
        }
22 64
        return $res;
23
    }
24
}
25