Completed
Push — master ( fa4061...e2ec10 )
by Sullivan
02:18
created

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 44
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 44
rs 8.8571
cc 1
eloc 39
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
                ->scalarNode('client')->defaultNull()->end()
25
                ->arrayNode('options')
26
                    ->addDefaultsIfNotSet()
27
                    ->children()
28
                        ->integerNode('timeout')->end()
29
                        ->booleanNode('production')->end()
30
                    ->end()
31
                ->end()
32
                ->arrayNode('paybox')
33
                    ->isRequired()
34
                    ->addDefaultsIfNotSet()
35
                    ->children()
36
                        ->scalarNode('version')
37
                            ->isRequired()
38
                            ->cannotBeEmpty()
39
                            ->validate()
40
                                ->ifNotInArray(array_keys(Paybox::VERSIONS))
41
                                ->thenInvalid('Invalid Paybox version')
42
                            ->end()
43
                        ->end()
44
                        ->scalarNode('site')->isRequired()->cannotBeEmpty()->end()
45
                        ->scalarNode('rang')->isRequired()->cannotBeEmpty()->end()
46
                        ->scalarNode('identifiant')->isRequired()->cannotBeEmpty()->end()
47
                        ->scalarNode('cle')->isRequired()->cannotBeEmpty()->end()
48
                        ->scalarNode('devise')
49
                            ->validate()
50
                                ->ifNotInArray(array_keys(Paybox::DEVISES))
51
                                ->thenInvalid('Invalid Paybox version')
52
                            ->end()
53
                        ->end()
54
                    ->end()
55
                ->end()
56
            ->end()
57
        ;
58
59
        return $treeBuilder;
60
    }
61
}
62