Completed
Pull Request — master (#64)
by .
09:24 queued 01:52
created

Configuration   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 3
dl 0
loc 62
ccs 42
cts 42
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B getConfigTreeBuilder() 0 56 1
1
<?php
2
3
namespace Facile\MongoDbBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6
use Symfony\Component\Config\Definition\ConfigurationInterface;
7
8
/**
9
 * Class Configuration.
10
 *
11
 * @internal
12
 */
13
final class Configuration implements ConfigurationInterface
14
{
15
    /**
16
     * {@inheritdoc}
17 12
     */
18
    public function getConfigTreeBuilder()
19 12
    {
20
        $readPreferenceValidOptions = ['primary', 'primaryPreferred', 'secondary', 'secondaryPreferred', 'nearest'];
21 12
22 12
        $treeBuilder = new TreeBuilder();
23
        $rootNode = $treeBuilder->root('mongo_db_bundle');
24 12
        $rootNode
25 12
            ->children()
26 12
                ->booleanNode('data_collection')->defaultTrue()->info('Disables Data Collection if needed')->end()
27 12
                ->arrayNode('clients')
28 12
                    ->isRequired()
29 12
                    ->requiresAtLeastOneElement()
30 12
                    ->useAttributeAsKey('name')
31 12
                    ->prototype('array')
32 12
                        ->children()
33 12
                            ->arrayNode('hosts')->info('Hosts addresses and ports')
34 12
                                ->prototype('array')
35 12
                                    ->children()
36 12
                                        ->scalarNode('host')->isRequired()->end()
37 12
                                        ->integerNode('port')->defaultValue(27017)->end()
38 12
                                    ->end()
39 12
                                ->end()
40 12
                            ->end()
41 12
                            ->scalarNode('uri')->defaultNull()->info('Overrides hosts configuration')->end()
42 12
                            ->scalarNode('username')->defaultValue('')->end()
43 12
                            ->scalarNode('password')->defaultValue('')->end()
44 12
                            ->scalarNode('authSource')->defaultNull()->info('Database name associated with the user’s credentials')->end()
45 12
                            ->scalarNode('readPreference')
46 12
                                ->defaultValue('primaryPreferred')
47 12
                                ->validate()
48 12
                                    ->ifNotInArray($readPreferenceValidOptions)
49 12
                                    ->thenInvalid('Invalid readPreference option %s, must be one of ['.implode(', ', $readPreferenceValidOptions).']')
50 12
                                ->end()
51 12
                            ->end()
52
                            ->scalarNode('replicaSet')->defaultNull()->end()
53 12
                            ->booleanNode('ssl')->defaultFalse()->end()
54 12
                            ->integerNode('connectTimeoutMS')->defaultNull()->end()
55 12
                        ->end()
56 12
                    ->end()
57 12
                ->end()
58 12
            ->end();
59 12
        $rootNode
60 12
            ->children()
61 12
                ->arrayNode('connections')->isRequired()->requiresAtLeastOneElement()
62
                    ->useAttributeAsKey('name')
63 12
                    ->prototype('array')
64
                        ->children()
65
                            ->scalarNode('client_name')->isRequired()->info('Desired client name')->end()
66
                            ->scalarNode('database_name')->isRequired()->info('Database name')->end()
67
                        ->end()
68
                    ->end()
69
                ->end()
70
            ->end();
71
72
        return $treeBuilder;
73
    }
74
}
75