Completed
Push — feature/rewrite ( 88e863...f6b662 )
by Alexandre
01:55
created

Configuration   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 41
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B getConfigTreeBuilder() 0 25 1
1
<?php
2
3
namespace Black\Bundle\PageBundle\Application\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
7
use Symfony\Component\Config\Definition\ConfigurationInterface;
8
9
/**
10
 * Class Configuration
11
 */
12
class Configuration implements ConfigurationInterface
13
{
14
    private $alias;
15
16
    /**
17
     * @param string $alias
18
     */
19
    public function __construct($alias)
20
    {
21
        $this->alias = $alias;
22
    }
23
24
    /**
25
     * {@inheritDoc}
26
     */
27
    public function getConfigTreeBuilder()
28
    {
29
        $treeBuilder = new TreeBuilder();
30
        $rootNode    = $treeBuilder->root($this->alias);
31
32
        $supportedDrivers = ['mongodb', 'orm'];
33
34
        $rootNode
35
            ->children()
36
37
                ->scalarNode('db_driver')
38
                    ->validate()
39
                        ->ifNotInArray($supportedDrivers)
40
                        ->thenInvalid('The database driver %s is not supported. Please choose one of ' . json_encode($supportedDrivers))
41
                    ->end()
42
                    ->isRequired()
43
                    ->cannotBeOverwritten()
44
                    ->cannotBeEmpty()
45
                ->end()
46
47
                ->scalarNode('page_class')->isRequired()->cannotBeEmpty()->end()
48
            ->end();
49
50
        return $treeBuilder;
51
    }
52
}
53