Passed
Pull Request — master (#4)
by Loick
08:30
created

Configuration::getConfigTreeBuilder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 54
Code Lines 49

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 49
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 54
rs 9.1127

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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