Completed
Pull Request — master (#23)
by Peter
10:14 queued 06:31
created

Configuration   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 50
ccs 15
cts 16
cp 0.9375
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getConfigTreeBuilder() 0 33 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
    private 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(): TreeBuilder
32
    {
33 1
        $tree_builder = new TreeBuilder(self::ROOT_NODE);
34
35 1
        if (method_exists($tree_builder, 'getRootNode')) {
36
            // Symfony 4.2 +
37
            $root_node = $tree_builder->getRootNode();
38
        } else {
39
            // Symfony 4.1 and below
40 1
            $root_node = $tree_builder->root(self::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 1
        $cache = $root_node->children()->scalarNode('cache');
44
        $cache
45 1
            ->cannotBeEmpty()
46 1
            ->defaultValue('%kernel.cache_dir%/GeoLite2-City.mmdb')
47
        ;
48
49 1
        $url = $root_node->children()->scalarNode('url');
50
        $url
51 1
            ->cannotBeEmpty()
52 1
            ->defaultValue('https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz')
53
        ;
54
55 1
        $locales = $root_node->children()->arrayNode('locales');
56 1
        $locales->prototype('scalar');
57
        $locales
58 1
            ->treatNullLike([])
59 1
            ->defaultValue(['%locale%'])
60
        ;
61
62 1
        return $tree_builder;
63
    }
64
}
65