KeyEnvVarProcessor   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getEnv() 0 12 3
A getProvidedTypes() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2019 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace Jose\Bundle\JoseFramework\EnvVarProcessor;
15
16
use Closure;
17
use Jose\Component\Core\JWK;
18
use Jose\Component\Core\JWKSet;
19
use RuntimeException;
20
use Symfony\Component\DependencyInjection\EnvVarProcessorInterface;
21
22
final class KeyEnvVarProcessor implements EnvVarProcessorInterface
23
{
24
    /**
25
     * {@inheritdoc}
26
     *
27
     * @throws RuntimeException if the prefix is not supported
28
     */
29
    public function getEnv($prefix, $name, Closure $getEnv)
30
    {
31
        $env = $getEnv($name);
32
        switch ($prefix) {
33
            case 'jwk':
34
                return JWK::createFromJson($env);
35
            case 'jwkset':
36
                return JWKSet::createFromJson($env);
37
            default:
38
                throw new RuntimeException(sprintf('Unsupported prefix "%s".', $prefix));
39
        }
40
    }
41
42
    public static function getProvidedTypes(): array
43
    {
44
        return [
45
            'jwk' => 'string',
46
            'jwkset' => 'string',
47
        ];
48
    }
49
}
50