Passed
Branch master (98ecdf)
by Michael
56:56
created

Configuration::getConfigTreeBuilder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
crap 2
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
    public function getConfigTreeBuilder()
30
    {
31
        $treeBuilder = new TreeBuilder();
32
        $rootNode = $treeBuilder->root('oslab_security_api');
33
        $this->addAuthenticationSection($rootNode);
34
35
        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
    protected function addAuthenticationSection(ArrayNodeDefinition $node)
46
    {
47
        $node->children()
48
            ->arrayNode('authentication')
49
            ->addDefaultsIfNotSet()
50
            ->children()
51
                ->scalarNode('method')
52
                    ->defaultValue('query')
53
                    ->isRequired()
54
                    ->cannotBeEmpty()
55
                    ->validate()
56
                    ->ifNotInArray(array('header', 'query'))
57
                        ->thenInvalid('Invalid method for security %s')
58
                    ->end()
59
                ->end()
60
                ->scalarNode('key_name')->defaultValue('key')->isRequired()->cannotBeEmpty()->end()
61
            ->end()
62
        ->end();
63
    }
64
}
65