Failed Conditions
Push — master ( 1cbd9b...1a86c5 )
by Florent
02:00
created

KeyEnvVarProcessor::getEnv()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 3
nop 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2017 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 Jose\Component\Core\JWK;
17
use Jose\Component\Core\JWKSet;
18
use Symfony\Component\DependencyInjection\EnvVarProcessorInterface;
19
20
/**
21
 * Class KeyEnvVarProcessor.
22
 */
23
final class KeyEnvVarProcessor implements EnvVarProcessorInterface
24
{
25
    public function getEnv($prefix, $name, \Closure $getEnv)
26
    {
27
        $env = $getEnv($name);
28
        switch ($prefix) {
29
            case 'jwk':
30
                return JWK::createFromJson($env);
31
            case 'jwkset':
32
                return JWKSet::createFromJson($env);
33
            default:
34
                throw new \RuntimeException(sprintf('Unsupported prefix "%s".', $prefix));
35
        }
36
    }
37
38
    public static function getProvidedTypes()
39
    {
40
        return [
41
            'jwk'    => 'string',
42
            'jwkset' => 'string',
43
        ];
44
    }
45
}
46