Completed
Push — master ( 479a96...af667a )
by
unknown
03:16
created

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 56

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 50
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 56
ccs 50
cts 50
cp 1
rs 8.9599
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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