Completed
Push — master ( a7eec1...845367 )
by Joel
09:19
created

Configuration::getRootNode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 6
rs 10
1
<?php
2
3
namespace RedirectionIO\Client\ProxySymfony\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Config...\Builder\NodeDefinition was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Config...ion\Builder\TreeBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Symfony\Component\Config\Definition\ConfigurationInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Config...\ConfigurationInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
/**
10
 * @internal
11
 */
12
final class Configuration implements ConfigurationInterface
13
{
14
    const ROOT_NAME = 'redirection_io';
15
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public function getConfigTreeBuilder()
20
    {
21
        $treeBuilder = new TreeBuilder(self::ROOT_NAME);
22
        $rootNode = $this->getRootNode($treeBuilder);
23
        $excludedPrefixes = ['/_wdt', '/_profiler', '/_error'];
24
25
        $rootNode
26
            ->children()
27
                ->scalarNode('project_key')
28
                    ->isRequired()
29
                    ->cannotBeEmpty()
30
                    ->info('Your project key that can be found at: https://redirection.io/manager/<organization>/<project>/instances')
31
                ->end()
32
                ->arrayNode('connections')
33
                    ->normalizeKeys(false)
34
                    ->useAttributeAsKey('name')
35
                    ->addDefaultChildrenIfNoneSet('default')
36
                    ->prototype('scalar')
37
                        ->info('a TCP or unix socket')
38
                        ->example('tcp://127.0.0.1:20301 or unix:///var/run/redirectionio_agent.sock')
39
                        ->isRequired()
40
                        ->cannotBeEmpty()
41
                        ->defaultValue('tcp://127.0.0.1:20301')
42
                    ->end()
43
                ->end()
44
                ->booleanNode('persist')
45
                    ->info('Persist client connections to be reuse on other requests')
46
                    ->defaultTrue()
47
                ->end()
48
                ->booleanNode('debug')
49
                    ->info('Throw exception if something wrong happens')
50
                    ->defaultValue('%kernel.debug%')
51
                ->end()
52
                ->booleanNode('match_on_response')
53
                    ->info('Allow match on response status rules')
54
                    ->defaultValue(false)
55
                ->end()
56
                ->arrayNode('excluded_prefixes')
57
                    ->info('Exclude a set of prefixes from processing')
58
                    ->prototype('scalar')->end()
59
                    ->validate()
60
                        ->always()
61
                        ->then(function ($v) use ($excludedPrefixes) { return array_unique(array_merge($excludedPrefixes, $v)); })
62
                    ->end()
63
                    ->defaultValue($excludedPrefixes)
64
                ->end()
65
                ->arrayNode('excluded_hosts')
66
                    ->info('Exclude a set of hosts from processing')
67
                    ->prototype('scalar')->end()
68
                ->end()
69
            ->end()
70
        ;
71
72
        return $treeBuilder;
73
    }
74
75
    /**
76
     * Returns the root node of TreeBuilder with backwards compatibility with Symfony < 4.3.
77
     */
78
    private function getRootNode(TreeBuilder $treeBuilder): NodeDefinition
79
    {
80
        if (method_exists($treeBuilder, 'getRootNode')) {
81
            return $treeBuilder->getRootNode();
82
        } else {
83
            return $treeBuilder->root(self::ROOT_NAME);
84
        }
85
    }
86
}
87