Configuration   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 1
c 4
b 0
f 0
lcom 0
cbo 3
dl 0
loc 47
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B getConfigTreeBuilder() 0 39 1
1
<?php
2
3
declare (strict_types = 1);
4
5
namespace HMLB\DDDBundle\DependencyInjection;
6
7
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
8
use Symfony\Component\Config\Definition\ConfigurationInterface;
9
10
/**
11
 * Configuration.
12
 *
13
 * @author Hugues Maignol <[email protected]>
14
 */
15
class Configuration implements ConfigurationInterface
16
{
17
    /**
18
     * Generates the configuration tree.
19
     *
20
     * @return TreeBuilder
21
     */
22
    public function getConfigTreeBuilder(): TreeBuilder
23
    {
24
        $treeBuilder = new TreeBuilder();
25
        $rootNode = $treeBuilder->root('hmlb_ddd');
26
27
        $supportedDrivers = [
28
            'orm',
29
            'mongodb',
30
        ];
31
32
        $rootNode
33
            ->children()
34
                ->arrayNode('persistence')
35
                    ->addDefaultsIfNotSet()
36
                    ->children()
37
                        ->booleanNode('persist_commands')->defaultTrue()->end()
38
                        ->booleanNode('persist_events')->defaultTrue()->end()
39
                        ->scalarNode('command_repository_service')
40
                            ->defaultValue('hmlb_ddd.repository.command.default')
41
                        ->end()
42
                        ->scalarNode('event_repository_service')
43
                            ->defaultValue('hmlb_ddd.repository.event.default')
44
                        ->end()
45
                    ->end()
46
                ->end()
47
                ->scalarNode('db_driver')
48
                    ->defaultValue('orm')
49
                    ->validate()
50
                        ->ifNotInArray($supportedDrivers)
51
                        ->thenInvalid(
52
                            'The driver %s is not supported. Please choose one of '.json_encode($supportedDrivers)
53
                        )
54
                    ->end()
55
                ->end()
56
57
            ->end();
58
59
        return $treeBuilder;
60
    }
61
}
62