Completed
Push — master ( fc0488...e7fa5b )
by Michael
10:16 queued 07:42
created

Configuration::addAuthenticationSection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 18
cts 18
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 17
nc 1
nop 1
crap 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