Failed Conditions
Push — master ( 84af72...50c060 )
by Denis
05:02
created

Configuration   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 97.22%

Importance

Changes 0
Metric Value
wmc 2
eloc 38
dl 0
loc 53
ccs 35
cts 36
cp 0.9722
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getConfigTreeBuilder() 0 48 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Artprima\PrometheusMetricsBundle\DependencyInjection;
6
7
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
8
use Symfony\Component\Config\Definition\ConfigurationInterface;
9
10
/**
11
 * This is the class that validates and merges configuration from your app/config files.
12
 *
13
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/configuration.html}
14
 */
15
class Configuration implements ConfigurationInterface
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20 1
    public function getConfigTreeBuilder()
21
    {
22 1
        $treeBuilder = new TreeBuilder('artprima_prometheus_metrics');
23 1
        if (method_exists($treeBuilder, 'getRootNode')) {
24 1
            $rootNode = $treeBuilder->getRootNode();
25
        } else {
26
            // BC for symfony/config < 4.2
27
            $rootNode = $treeBuilder->root('artprima_prometheus_metrics');
28
        }
29
30 1
        $supportedTypes = ['in_memory', 'apcu', 'redis'];
31
32
        $rootNode
33 1
            ->children()
34 1
                ->scalarNode('namespace')
35 1
                    ->isRequired()
36 1
                    ->cannotBeEmpty()
37 1
                ->end()
38 1
                ->scalarNode('type')
39 1
                    ->validate()
40 1
                        ->ifNotInArray($supportedTypes)
41 1
                        ->thenInvalid('The type %s is not supported. Please choose one of '.json_encode($supportedTypes))
42 1
                    ->end()
43 1
                    ->defaultValue('in_memory')
44 1
                    ->cannotBeEmpty()
45 1
                ->end()
46 1
                ->arrayNode('redis')
47 1
                    ->children()
48 1
                        ->scalarNode('host')->end()
49 1
                        ->integerNode('port')->end()
50 1
                        ->floatNode('timeout')->end()
51 1
                        ->floatNode('read_timeout')->end()
52 1
                        ->booleanNode('persistent_connections')->end()
53 1
                        ->scalarNode('password')->end()
54 1
                        ->integerNode('database')->end()
55 1
                    ->end()
56 1
                ->end()
57 1
                ->arrayNode('ignored_routes')
58 1
                    ->prototype('scalar')->end()
59 1
                    ->defaultValue(['prometheus_bundle_prometheus'])
60 1
                ->end()
61 1
            ->end();
62
63
        // Here you should define the parameters that are allowed to
64
        // configure your bundle. See the documentation linked above for
65
        // more information on that topic.
66
67 1
        return $treeBuilder;
68
    }
69
}
70