Completed
Push — master ( 765a87...b5032e )
by Peter
04:25
created

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 26
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 28
ccs 26
cts 26
cp 1
rs 8.8571
c 1
b 0
f 1
cc 1
eloc 26
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * GpsLab component.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2016, Peter Gribanov
7
 * @license   http://opensource.org/licenses/MIT
8
 */
9
10
namespace GpsLab\Bundle\DateBundle\DependencyInjection;
11
12
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
13
use Symfony\Component\Config\Definition\ConfigurationInterface;
14
15
class Configuration implements ConfigurationInterface
16
{
17
    /**
18
     * Config tree builder.
19
     *
20
     * Example config:
21
     *
22
     * gpslab_date:
23
     *     time_zone: 'Europe/Moscow'
24
     *     cookie:
25
     *         used: true
26
     *         name: '_time_zone_name'
27
     *         offset: '_time_zone_offset'
28
     *
29
     * @return TreeBuilder
30
     */
31 1
    public function getConfigTreeBuilder()
32
    {
33 1
        return (new TreeBuilder())
34 1
            ->root('gpslab_date')
35 1
            ->addDefaultsIfNotSet()
36 1
            ->children()
37 1
                ->scalarNode('time_zone')
38 1
                    ->defaultValue(date_default_timezone_get())
39 1
                ->end()
40 1
                ->arrayNode('cookie')
41 1
                    ->addDefaultsIfNotSet()
42 1
                    ->children()
43 1
                        ->scalarNode('used')
44 1
                            ->defaultValue(true)
45 1
                        ->end()
46 1
                        ->scalarNode('name')
47 1
                            ->cannotBeEmpty()
48 1
                            ->defaultValue('_time_zone_name')
49 1
                        ->end()
50 1
                        ->scalarNode('offset')
51 1
                            ->cannotBeEmpty()
52 1
                            ->defaultValue('_time_zone_offset')
53 1
                        ->end()
54 1
                    ->end()
55 1
                ->end()
56 1
            ->end()
57 1
        ->end();
58
    }
59
}
60