Completed
Pull Request — master (#3)
by Sullivan
02:31
created

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 43
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 43
rs 8.8571
cc 1
eloc 38
nc 1
nop 0
1
<?php
2
3
namespace Nexy\PayboxDirect\Bundle\DependencyInjection;
4
5
use Nexy\PayboxDirect\Paybox;
6
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
7
use Symfony\Component\Config\Definition\ConfigurationInterface;
8
9
/**
10
 * @author Sullivan Senechal <[email protected]>
11
 */
12
final class Configuration implements ConfigurationInterface
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17
    public function getConfigTreeBuilder()
18
    {
19
        $treeBuilder = new TreeBuilder();
20
        $rootNode = $treeBuilder->root('nexy_paybox_direct');
21
22
        $rootNode
23
            ->children()
24
                ->arrayNode('client')
25
                    ->addDefaultsIfNotSet()
26
                    ->children()
27
                        ->integerNode('timeout')->end()
28
                        ->booleanNode('production')->end()
29
                    ->end()
30
                ->end()
31
                ->arrayNode('paybox')
32
                    ->isRequired()
33
                    ->addDefaultsIfNotSet()
34
                    ->children()
35
                        ->scalarNode('version')
36
                            ->isRequired()
37
                            ->cannotBeEmpty()
38
                            ->validate()
39
                                ->ifNotInArray(array_keys(Paybox::VERSIONS))
40
                                ->thenInvalid('Invalid Paybox version')
41
                            ->end()
42
                        ->end()
43
                        ->scalarNode('site')->isRequired()->cannotBeEmpty()->end()
44
                        ->scalarNode('rang')->isRequired()->cannotBeEmpty()->end()
45
                        ->scalarNode('identifiant')->isRequired()->cannotBeEmpty()->end()
46
                        ->scalarNode('cle')->isRequired()->cannotBeEmpty()->end()
47
                        ->scalarNode('devise')
48
                            ->validate()
49
                                ->ifNotInArray(array_keys(Paybox::DEVISES))
50
                                ->thenInvalid('Invalid Paybox version')
51
                            ->end()
52
                        ->end()
53
                    ->end()
54
                ->end()
55
            ->end()
56
        ;
57
58
        return $treeBuilder;
59
    }
60
}
61