Completed
Pull Request — master (#64)
by .
03:42
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
 * @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