Passed
Push — develop ( bc580a...dfcb3d )
by Denis
16:12 queued 10:55
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 1
    public function getConfigTreeBuilder()
21
    {
22 1
        $treeBuilder = new TreeBuilder('artprima_prometheus_metrics');
23 1
        $rootNode = $treeBuilder->getRootNode();
24
25 1
        $supportedTypes = ['in_memory', 'apcu', 'redis'];
26
27
        $rootNode
28 1
            ->children()
29 1
                ->scalarNode('namespace')
30 1
                    ->isRequired()
31 1
                    ->cannotBeEmpty()
32 1
                ->end()
33 1
                ->scalarNode('type')
34 1
                    ->validate()
35 1
                        ->ifNotInArray($supportedTypes)
36 1
                        ->thenInvalid('The type %s is not supported. Please choose one of '.json_encode($supportedTypes))
37 1
                    ->end()
38 1
                    ->defaultValue('in_memory')
39 1
                    ->cannotBeEmpty()
40 1
                ->end()
41 1
                ->arrayNode('redis')
42 1
                    ->children()
43 1
                        ->scalarNode('host')->end()
44 1
                        ->integerNode('port')->end()
45 1
                        ->floatNode('timeout')->end()
46 1
                        ->floatNode('read_timeout')->end()
47 1
                        ->booleanNode('persistent_connections')->end()
48 1
                        ->scalarNode('password')->end()
49 1
                        ->integerNode('database')->end()
50 1
                    ->end()
51 1
                ->end()
52 1
                ->arrayNode('ignored_routes')
53 1
                    ->prototype('scalar')->end()
54 1
                    ->defaultValue(['prometheus_bundle_prometheus'])
55 1
                ->end()
56 1
            ->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 1
        return $treeBuilder;
63
    }
64
}
65