Completed
Push — master ( 436bef...a88b2a )
by Peter
03:50 queued 03:48
created

Configuration   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 49
ccs 22
cts 24
cp 0.9167
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getConfigTreeBuilder() 0 32 2
1
<?php
2
/**
3
 * GpsLab component.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2017, Peter Gribanov
7
 * @license   http://opensource.org/licenses/MIT
8
 */
9
10
namespace GpsLab\Bundle\GeoIP2Bundle\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
    const ROOT_NODE = 'gpslab_geoip';
18
19
    /**
20
     * Config tree builder.
21
     *
22
     * Example config:
23
     *
24
     * gpslab_geoip:
25
     *     cache: '%kernel.cache_dir%/GeoLite2-City.mmdb'
26
     *     url: 'https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz'
27
     *     locales: [ '%locale%' ]
28
     *
29
     * @return TreeBuilder
30
     */
31 1
    public function getConfigTreeBuilder()
32
    {
33 1
        $treeBuilder = new TreeBuilder(static::ROOT_NODE);
34
35 1
        if (method_exists($treeBuilder, 'getRootNode')) {
36
            // Symfony 4.2 +
37
            $rootNode = $treeBuilder->getRootNode();
38
        } else {
39
            // Symfony 4.1 and below
40 1
            $rootNode = $treeBuilder->root(static::ROOT_NODE);
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Component\Config...der\TreeBuilder::root() has been deprecated with message: since Symfony 4.3, pass the root name to the constructor instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
41
        }
42
43
        return
44 1
            $rootNode
45 1
                ->children()
46 1
                    ->scalarNode('cache')
47 1
                        ->cannotBeEmpty()
48 1
                        ->defaultValue('%kernel.cache_dir%/GeoLite2-City.mmdb')
49 1
                    ->end()
50 1
                    ->scalarNode('url')
51 1
                        ->cannotBeEmpty()
52 1
                        ->defaultValue('https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz')
53 1
                    ->end()
54 1
                    ->arrayNode('locales')
55 1
                        ->treatNullLike([])
56 1
                        ->prototype('scalar')->end()
57 1
                        ->defaultValue(['%locale%'])
58 1
                    ->end()
59 1
                ->end()
60 1
            ->end()
61 1
        ;
62
    }
63
}
64