Completed
Push — master ( c7a8ed...7c53a3 )
by Florent
08:28
created

Configuration::addJWKSetSourcesSection()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 12

Duplication

Lines 15
Ratio 100 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
c 1
b 1
f 1
dl 15
loc 15
rs 9.4285
cc 2
eloc 12
nc 2
nop 2
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;
13
14
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
15
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
16
use Symfony\Component\Config\Definition\ConfigurationInterface;
17
18
final class Configuration implements ConfigurationInterface
19
{
20
    /**
21
     * @var \SpomkyLabs\JoseBundle\DependencyInjection\JWKSource\JWKSourceInterface[]
22
     */
23
    private $jwk_sources;
24
25
    /**
26
     * @var \SpomkyLabs\JoseBundle\DependencyInjection\JWKSetSource\JWKSetSourceInterface[]
27
     */
28
    private $jwk_set_sources;
29
30
    /**
31
     * @var string
32
     */
33
    private $alias;
34
35
    /**
36
     * Configuration constructor.
37
     *
38
     * @param string                                                                          $alias
39
     * @param \SpomkyLabs\JoseBundle\DependencyInjection\JWKSource\JWKSourceInterface[]       $jwk_sources
40
     * @param \SpomkyLabs\JoseBundle\DependencyInjection\JWKSetSource\JWKSetSourceInterface[] $jwk_set_sources
41
     */
42
    public function __construct($alias, array $jwk_sources, array $jwk_set_sources)
43
    {
44
        $this->alias = $alias;
45
        $this->jwk_sources = $jwk_sources;
46
        $this->jwk_set_sources = $jwk_set_sources;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function getConfigTreeBuilder()
53
    {
54
        $treeBuilder = new TreeBuilder();
55
        $rootNode = $treeBuilder->root($this->alias);
56
57
        $this->addJWKSourcesSection($rootNode, $this->jwk_sources);
58
        $this->addJWKSetSourcesSection($rootNode, $this->jwk_set_sources);
59
60
        $rootNode
61
            ->children()
62
                ->arrayNode('compression_methods')
63
                    ->info('A list of enabled compression methods. Supported methods are: "DEF" (recommended), "GZ" and "ZLIB".')
64
                    ->prototype('scalar')
65
                    ->end()
66
                    ->treatNullLike([])
67
                ->end()
68
                ->end()
69
            ->end();
70
71
        return $treeBuilder;
72
    }
73
74
    /**
75
     * @param \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition          $node
76
     * @param \SpomkyLabs\JoseBundle\DependencyInjection\JWKSource\JWKSourceInterface[] $jwk_sources
77
     */
78 View Code Duplication
    private function addJWKSourcesSection(ArrayNodeDefinition $node, array $jwk_sources)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
79
    {
80
        $sourceNodeBuilder = $node
81
            ->fixXmlConfig('source')
82
            ->children()
83
            ->arrayNode('keys')
84
            ->useAttributeAsKey('name')
85
            ->prototype('array')
86
            ->performNoDeepMerging()
87
            ->children();
88
        foreach ($jwk_sources as $name => $source) {
89
            $sourceNode = $sourceNodeBuilder->arrayNode($name)->canBeUnset();
90
            $source->addConfiguration($sourceNode);
91
        }
92
    }
93
94
    /**
95
     * @param \Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition                $node
96
     * @param \SpomkyLabs\JoseBundle\DependencyInjection\JWKSetSource\JWKSetSourceInterface[] $jwk_set_sources
97
     */
98 View Code Duplication
    private function addJWKSetSourcesSection(ArrayNodeDefinition $node, array $jwk_set_sources)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
99
    {
100
        $sourceNodeBuilder = $node
101
            ->fixXmlConfig('source')
102
            ->children()
103
            ->arrayNode('key_sets')
104
            ->useAttributeAsKey('name')
105
            ->prototype('array')
106
            ->performNoDeepMerging()
107
            ->children();
108
        foreach ($jwk_set_sources as $name => $source) {
109
            $sourceNode = $sourceNodeBuilder->arrayNode($name)->canBeUnset();
110
            $source->addConfiguration($sourceNode);
111
        }
112
    }
113
}
114