Completed
Push — master ( 551cf0...63e1d5 )
by Denis
26:27 queued 13:11
created

Configuration   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 1
eloc 35
c 3
b 0
f 0
dl 0
loc 48
ccs 34
cts 34
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getConfigTreeBuilder() 0 43 1
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 3
    public function getConfigTreeBuilder()
21
    {
22 3
        $treeBuilder = new TreeBuilder('artprima_prometheus_metrics');
23 3
        $rootNode = $treeBuilder->getRootNode();
24
25 3
        $supportedTypes = ['in_memory', 'apcu', 'redis'];
26
27
        $rootNode
28 3
            ->children()
29 3
                ->scalarNode('namespace')
30 3
                    ->isRequired()
31 3
                    ->cannotBeEmpty()
32 3
                ->end()
33 3
                ->scalarNode('type')
34 3
                    ->validate()
35 3
                        ->ifNotInArray($supportedTypes)
36 3
                        ->thenInvalid('The type %s is not supported. Please choose one of '.json_encode($supportedTypes))
37 3
                    ->end()
38 3
                    ->defaultValue('in_memory')
39 3
                    ->cannotBeEmpty()
40 3
                ->end()
41 3
                ->arrayNode('redis')
42 3
                    ->children()
43 3
                        ->scalarNode('host')->end()
44 3
                        ->integerNode('port')->end()
45 3
                        ->floatNode('timeout')->end()
46 3
                        ->floatNode('read_timeout')->end()
47 3
                        ->booleanNode('persistent_connections')->end()
48 3
                        ->scalarNode('password')->end()
49 3
                        ->integerNode('database')->end()
50 3
                    ->end()
51 3
                ->end()
52 3
                ->arrayNode('ignored_routes')
53 3
                    ->prototype('scalar')->end()
54 3
                    ->defaultValue(['prometheus_bundle_prometheus'])
55 3
                ->end()
56 3
            ->end();
57
58
        // Here you should define the parameters that are allowed to
59
        // configure your bundle. See the documentation linked above for
60
        // more information on that topic.
61
62 3
        return $treeBuilder;
63
    }
64
}
65