Configuration::getConfigTreeBuilder()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 24
CRAP Score 1
Metric Value
dl 0
loc 29
ccs 24
cts 24
cp 1
rs 8.8571
cc 1
eloc 25
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of the xAPI package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
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 Xabbuh\XApi\Bundle\ClientBundle\DependencyInjection;
13
14
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
15
use Symfony\Component\Config\Definition\ConfigurationInterface;
16
17
/**
18
 * XApi client bundle configuration.
19
 *
20
 * @author Christian Flothmann <[email protected]>
21
 */
22
class Configuration implements ConfigurationInterface
23
{
24
    /**
25
     * {@inheritDoc}
26
     */
27 9
    public function getConfigTreeBuilder()
28
    {
29 9
        $treeBuilder = new TreeBuilder();
30 9
        $rootNode = $treeBuilder->root('xabbuh_xapi_client');
31
32
        $rootNode
33 9
            ->fixXmlConfig('client')
34 9
            ->children()
35 9
                ->arrayNode('clients')
36 9
                    ->useAttributeAsKey('name')
37 9
                    ->prototype('array')
38 9
                        ->children()
39 9
                            ->scalarNode('base_url')->isRequired()->end()
40 9
                            ->scalarNode('username')->end()
41 9
                            ->scalarNode('password')->end()
42 9
                            ->scalarNode('version')
43 9
                                ->defaultValue('1.0.1')
44 9
                                ->validate()
45 9
                                    ->ifNotInArray(array('1.0.0', '1.0.1'))
46 9
                                    ->thenInvalid('Version must be on of 1.0.0, 1.0.1')
47 9
                                ->end()
48 9
                            ->end()
49 9
                        ->end()
50 9
                    ->end()
51 9
                ->end()
52 9
            ->end();
53
54 9
        return $treeBuilder;
55
    }
56
}
57