Passed
Push — master ( f80f70...56399a )
by Thomas Mauro
03:05 queued 10s
created

base64url_decode.php ➔ base64url_decode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 10
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\OpenIDClient;
6
7
use function base64_decode;
8
use Facile\OpenIDClient\Exception\RuntimeException;
9
use function str_pad;
10
use function strlen;
11
use function strtr;
12
13
function base64url_decode(string $data): string
14
{
15 5
    $decoded = base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '='), true);
16
17 5
    if (false === $decoded) {
18
        throw new RuntimeException('Unable to base64url_decode');
19
    }
20
21 5
    return $decoded;
22
}
23