Base64UrlEncoding   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 14
ccs 7
cts 7
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A decode() 0 7 2
A encode() 0 3 1
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