Passed
Pull Request — master (#16)
by BENOIT
02:12
created

get_options_from_input()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
ccs 0
cts 0
cp 0
crap 6
1
<?php
2
3
namespace BenTools\MercurePHP;
4
5
use Lcobucci\JWT\Signer;
6
use Symfony\Component\Console\Input\InputInterface;
7 2
8 2
function nullify($input)
9
{
10 2
    if (!\is_scalar($input)) {
11 2
        return $input;
12
    }
13
    if ((string) $input === '') {
14
        return null;
15
    }
16
17
    return $input;
18
}
19
20
function get_signer(string $algorithm): Signer
21
{
22
    $map = [
23
        'HS256' => new Signer\Hmac\Sha256(),
24
        'RS512' => new Signer\Rsa\Sha512(),
25
    ];
26
27
    if (!isset($map[$algorithm])) {
28
        throw new \InvalidArgumentException(\sprintf('Invalid algorithm %s.', $algorithm));
29
    }
30
31
    return $map[$algorithm];
32
}
33
34
function without_nullish_values(array $array): array
35
{
36
    return \array_filter(
37
        $array,
38
        fn($value) => null !== nullify($value) && false !== $value
39
    );
40
}
41
42
function get_options_from_input(InputInterface $input): array
43
{
44
    return \array_filter(
45
        $input->getOptions(),
46
        fn($value) => null !== nullify($value) && false !== $value
47
    );
48
}
49