Passed
Push — master ( 0e7627...09a47c )
by BENOIT
01:58
created

get_signer()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 6
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 12
rs 10
ccs 0
cts 0
cp 0
crap 6
1
<?php
2
3
namespace BenTools\MercurePHP;
4
5
use Lcobucci\JWT\Signer;
6
7 2
function nullify($input)
8 2
{
9
    if (!\is_scalar($input)) {
10 2
        return $input;
11 2
    }
12
    if ((string) $input === '') {
13
        return null;
14
    }
15
16
    return $input;
17
}
18
19
function get_signer(string $algorithm): Signer
20
{
21
    $map = [
22
        'HS256' => new Signer\Hmac\Sha256(),
23
        'RS512' => new Signer\Rsa\Sha512(),
24
    ];
25
26
    if (!isset($map[$algorithm])) {
27
        throw new \InvalidArgumentException(\sprintf('Invalid algorithm %s.', $algorithm));
28
    }
29
30
    return $map[$algorithm];
31
}
32