ApplicationConfiguration::getConfigTreeBuilder()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 19
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 25
rs 9.6333
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: nicolas
5
 * Date: 18/02/17
6
 * Time: 07:26
7
 */
8
9
namespace Devgiants\Configuration;
10
11
12
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
13
use Symfony\Component\Config\Definition\ConfigurationInterface;
14
15
class ApplicationConfiguration implements ConfigurationInterface
16
{
17
    const ROOT_NODE = 'configuration';
18
    const NODE_NAME = 'name';
19
    const NODE_DEFAULT_VALUE = 'default_value';
20
21
    const HOST = [
22
        self::NODE_NAME => 'host',
23
        self::NODE_DEFAULT_VALUE => '192.168.1.1'
24
    ];
25
26
	const USER = [
27
		self::NODE_NAME => 'user',
28
		self::NODE_DEFAULT_VALUE => 'admin'
29
	];
30
31
    const PASSWORD = "password";
32
33
34
    public function getConfigTreeBuilder()
35
    {
36
        $treeBuilder = new TreeBuilder();
37
        $rootNode = $treeBuilder->root(static::ROOT_NODE);
38
39
        // add node definitions to the root of the tree
40
        $rootNode
41
            ->children()
42
                ->scalarNode(static::HOST[static::NODE_NAME])
43
                    ->defaultValue(static::HOST[static::NODE_DEFAULT_VALUE])
44
                    ->info('Contains the Livebox IP address or local DNS name. Default to 192.168.1.1')
45
                ->end()
46
		        ->scalarNode(static::USER[static::NODE_NAME])
47
			        ->defaultValue(static::USER[static::NODE_DEFAULT_VALUE])
48
			        ->info('Contains user for connecting. Default to admin')
49
		        ->end()
50
		        ->scalarNode(static::PASSWORD)
51
			        ->info('Contains password for connecting')
52
			        ->isRequired()
53
			        ->cannotBeEmpty()
54
		        ->end()
55
            ->end()
56
        ;
57
58
        return $treeBuilder;
59
    }
60
}