Completed
Push — master ( b288e2...4e6c2b )
by Michael
05:02 queued 02:08
created

Configuration   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 41
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfigTreeBuilder() 0 8 1
A addAuthenticationSection() 0 19 1
1
<?php
2
3
/*
4
 * This file is part of the OsLabSecurityApiBundle package.
5
 *
6
 * (c) OsLab <https://github.com/OsLab>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace OsLab\SecurityApiBundle\DependencyInjection;
13
14
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
15
use Symfony\Component\Config\Definition\ConfigurationInterface;
16
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
17
18
/**
19
 * This class validates configuration.
20
 *
21
 * @author Michael COULLERET <[email protected]>
22
 * @author Florent DESPIERRES <[email protected]>
23
 */
24
class Configuration implements ConfigurationInterface
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29 6
    public function getConfigTreeBuilder()
30
    {
31 6
        $treeBuilder = new TreeBuilder();
32 6
        $rootNode = $treeBuilder->root('oslab_security_api');
33 6
        $this->addAuthenticationSection($rootNode);
34
35 6
        return $treeBuilder;
36
    }
37
38
    /**
39
     * Adds the config of soap to global config.
40
     *
41
     * @param ArrayNodeDefinition $node The root element for the config nodes.
42
     *
43
     * @return void
44
     */
45 6
    protected function addAuthenticationSection(ArrayNodeDefinition $node)
46
    {
47 6
        $node->children()
48 6
            ->arrayNode('authentication')
49 6
            ->addDefaultsIfNotSet()
50 6
            ->children()
51 6
                ->scalarNode('method')
52 6
                    ->defaultValue('query')
53 6
                    ->isRequired()
54 6
                    ->cannotBeEmpty()
55 6
                    ->validate()
56 6
                    ->ifNotInArray(array('header', 'query'))
57 6
                        ->thenInvalid('Invalid method for security %s')
58 6
                    ->end()
59 6
                ->end()
60 6
                ->scalarNode('key_name')->defaultValue('key')->isRequired()->cannotBeEmpty()->end()
61 6
            ->end()
62 6
        ->end();
63 6
    }
64
}
65