Configuration::addAuthenticationSection()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 16
cts 16
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\ArrayNodeDefinition;
15
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
16
use Symfony\Component\Config\Definition\ConfigurationInterface;
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
    protected function addAuthenticationSection(ArrayNodeDefinition $node)
44
    {
45 6
        $node->children()
46
            ->arrayNode('authentication')
47 6
            ->addDefaultsIfNotSet()
48 6
            ->children()
49 6
                ->scalarNode('method')
50 6
                    ->defaultValue('query')
51 6
                    ->isRequired()
52 6
                    ->cannotBeEmpty()
53 6
                    ->validate()
54 6
                    ->ifNotInArray(['header', 'query'])
55 6
                        ->thenInvalid('Invalid method for security %s')
56 6
                    ->end()
57 6
                ->end()
58 6
                ->scalarNode('key_name')->defaultValue('key')->isRequired()->cannotBeEmpty()->end()
59 6
            ->end()
60 6
        ->end();
61 6
    }
62
}
63