Completed
Pull Request — master (#64)
by .
03:42
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 50
cts 50
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
 * @internal
11
 */
12
final class Configuration implements ConfigurationInterface
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17 13
    public function getConfigTreeBuilder()
18
    {
19 13
        $readPreferenceValidOptions = ['primary', 'primaryPreferred', 'secondary', 'secondaryPreferred', 'nearest'];
20
21 13
        $treeBuilder = new TreeBuilder();
22 13
        $rootNode = $treeBuilder->root('mongo_db_bundle');
23
        $rootNode
24 13
            ->children()
25 13
                ->booleanNode('data_collection')->defaultTrue()->info('Disables Data Collection if needed')->end()
26 13
                ->arrayNode('clients')
27 13
                    ->isRequired()
28 13
                    ->requiresAtLeastOneElement()
29 13
                    ->useAttributeAsKey('name')
30 13
                    ->prototype('array')
31 13
                        ->children()
32 13
                            ->arrayNode('hosts')->info('Hosts addresses and ports')
33 13
                                ->prototype('array')
34 13
                                    ->children()
35 13
                                        ->scalarNode('host')->isRequired()->end()
36 13
                                        ->integerNode('port')->defaultValue(27017)->end()
37 13
                                    ->end()
38 13
                                ->end()
39 13
                            ->end()
40 13
                            ->scalarNode('uri')->defaultNull()->info('Overrides hosts configuration')->end()
41 13
                            ->scalarNode('username')->defaultValue('')->end()
42 13
                            ->scalarNode('password')->defaultValue('')->end()
43 13
                            ->scalarNode('authSource')->defaultNull()->info('Database name associated with the user’s credentials')->end()
44 13
                            ->scalarNode('readPreference')
45 13
                                ->defaultValue('primaryPreferred')
46 13
                                ->validate()
47 13
                                    ->ifNotInArray($readPreferenceValidOptions)
48 13
                                    ->thenInvalid('Invalid readPreference option %s, must be one of [' . implode(", ", $readPreferenceValidOptions) . ']')
49 13
                                ->end()
50 13
                            ->end()
51 13
                            ->scalarNode('replicaSet')->defaultNull()->end()
52 13
                            ->booleanNode('ssl')->defaultFalse()->end()
53 13
                            ->integerNode('connectTimeoutMS')->defaultNull()->end()
54 13
                        ->end()
55 13
                    ->end()
56 13
                ->end()
57 13
            ->end();
58
        $rootNode
59 13
            ->children()
60 13
                ->arrayNode('connections')->isRequired()->requiresAtLeastOneElement()
61 13
                    ->useAttributeAsKey('name')
62 13
                    ->prototype('array')
63 13
                        ->children()
64 13
                            ->scalarNode('client_name')->isRequired()->info('Desired client name')->end()
65 13
                            ->scalarNode('database_name')->isRequired()->info('Database name')->end()
66 13
                        ->end()
67 13
                    ->end()
68 13
                ->end()
69 13
            ->end();
70
71 13
        return $treeBuilder;
72
    }
73
}
74