RandomKeySet   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getKeySet() 0 4 1
A createDefinition() 0 22 2
A addConfiguration() 0 22 1
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2016 Spomky-Labs
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license.  See the LICENSE file for details.
10
 */
11
12
namespace SpomkyLabs\JoseBundle\DependencyInjection\Source\JWKSetSource;
13
14
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Definition;
17
use Symfony\Component\DependencyInjection\Reference;
18
19
final class RandomKeySet extends AbstractJWKSetSource
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function createDefinition(ContainerBuilder $container, array $config)
25
    {
26
        if (true === $config['is_rotatable']) {
27
            $definition = new Definition('Jose\Object\RotatableJWKSet');
28
            $method = 'createRotatableKeySet';
29
        } else {
30
            $definition = new Definition('Jose\Object\StorableJWKSet');
31
            $method = 'createStorableKeySet';
32
        }
33
34
        $definition->setFactory([
35
            new Reference('jose.factory.jwk'),
36
            $method,
37
        ]);
38
        $definition->setArguments([
39
            $config['storage_path'],
40
            $config['key_configuration'],
41
            $config['nb_keys'],
42
        ]);
43
44
        return $definition;
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function getKeySet()
51
    {
52
        return 'auto';
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function addConfiguration(NodeDefinition $node)
59
    {
60
        parent::addConfiguration($node);
61
        $node
62
            ->children()
63
                ->booleanNode('is_rotatable')
64
                    ->info('If true, the service will be a rotatable key, else just storable.')
65
                    ->defaultFalse()
66
                ->end()
67
                ->integerNode('nb_keys')
68
                    ->info('Number of keys in the key set.')
69
                    ->isRequired()
70
                    ->min(1)
71
                ->end()
72
                ->scalarNode('storage_path')->isRequired()->end()
73
                ->arrayNode('key_configuration')
74
                    ->defaultValue([])
75
                    ->useAttributeAsKey('key')
76
                    ->prototype('variable')->end()
77
                ->end()
78
            ->end();
79
    }
80
}
81