Failed Conditions
Push — master ( d9377e...587e80 )
by Florent
02:05
created

KeyFile   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 47
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createDefinition() 0 15 1
A getKey() 0 4 1
A addConfiguration() 0 14 1
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\KeyManagement\DependencyInjection\Source\JWKSource;
15
16
use Jose\Bundle\JoseFramework\DependencyInjection\Source\AbstractSource;
17
use Jose\Component\KeyManagement\JWKFactory;
18
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
19
use Symfony\Component\DependencyInjection\ContainerBuilder;
20
use Symfony\Component\DependencyInjection\Definition;
21
use Symfony\Component\DependencyInjection\Reference;
22
23
/**
24
 * Class KeyFile.
25
 */
26
final class KeyFile extends AbstractSource implements JWKSourceInterface
27
{
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function createDefinition(ContainerBuilder $container, array $config): Definition
32
    {
33
        $definition = new Definition(JWK::class);
34
        $definition->setFactory([
35
            new Reference(JWKFactory::class),
36
            'createFromKeyFile',
37
        ]);
38
        $definition->setArguments([
39
            $config['path'],
40
            $config['password'],
41
            $config['additional_values'],
42
        ]);
43
44
        return $definition;
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function getKey(): string
51
    {
52
        return 'file';
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function addConfiguration(NodeDefinition $node)
59
    {
60
        parent::addConfiguration($node);
61
        $node
62
            ->children()
63
                ->scalarNode('path')->isRequired()->end()
64
                ->scalarNode('password')->defaultNull()->end()
65
                ->arrayNode('additional_values')
66
                    ->defaultValue([])
67
                    ->useAttributeAsKey('key')
68
                    ->prototype('variable')->end()
69
                ->end()
70
            ->end();
71
    }
72
}
73