Passed
Push — master ( da9ebc...eab3b6 )
by Tobias
02:14
created

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 95
Code Lines 90

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 95
rs 8.4117
c 0
b 0
f 0
cc 1
eloc 90
nc 1
nop 0

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
declare(strict_types=1);
4
5
/*
6
 * This file is part of Ekino New Relic bundle.
7
 *
8
 * (c) Ekino - Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Ekino\NewRelicBundle\DependencyInjection;
15
16
use Psr\Log\LogLevel;
17
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
18
use Symfony\Component\Config\Definition\ConfigurationInterface;
19
20
class Configuration implements ConfigurationInterface
21
{
22
    public function getConfigTreeBuilder(): TreeBuilder
23
    {
24
        $treeBuilder = new TreeBuilder();
25
        $rootNode = $treeBuilder->root('ekino_new_relic');
26
27
        $rootNode
28
            ->fixXmlConfig('deployment_name')
0 ignored issues
show
Bug introduced by
The method fixXmlConfig() does not exist on Symfony\Component\Config...\Builder\NodeDefinition. It seems like you code against a sub-type of Symfony\Component\Config...\Builder\NodeDefinition such as Symfony\Component\Config...der\ArrayNodeDefinition. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
            ->/** @scrutinizer ignore-call */ 
29
              fixXmlConfig('deployment_name')
Loading history...
29
            ->children()
30
                ->booleanNode('enabled')->defaultTrue()->end()
31
                ->scalarNode('interactor')->end()
32
                ->booleanNode('twig')->defaultValue(\class_exists('\Twig_Environment'))->end()
33
                ->scalarNode('api_key')->defaultValue(false)->end()
34
                ->scalarNode('license_key')->defaultValue(null)->end()
35
                ->scalarNode('application_name')->defaultValue(null)->end()
36
                ->arrayNode('deployment_names')
37
                    ->prototype('scalar')
38
                    ->end()
39
                    ->beforeNormalization()
40
                        ->ifTrue(function ($v) { return !\is_array($v); })
41
                        ->then(function ($v) { return \array_values(\array_filter(\explode(';', $v))); })
42
                    ->end()
43
                ->end()
44
                ->scalarNode('xmit')->defaultValue(false)->end()
45
                ->booleanNode('logging')
46
                    ->info('Write logs to a PSR3 logger whenever we send data to NewRelic.')
47
                    ->defaultFalse()
48
                ->end()
49
                ->arrayNode('exceptions')
50
                    ->canBeDisabled()
51
                ->end()
52
                ->arrayNode('commands')
53
                    ->canBeDisabled()
54
                    ->children()
55
                        ->arrayNode('ignored_commands')
56
                            ->prototype('scalar')
57
                            ->end()
58
                            ->beforeNormalization()
59
                                ->ifTrue(function ($v) { return !\is_array($v); })
60
                                ->then(function ($v) { return (array) $v; })
61
                            ->end()
62
                        ->end()
63
                    ->end()
64
                ->end()
65
                ->arrayNode('deprecations')
66
                    ->canBeDisabled()
67
                ->end()
68
                ->arrayNode('http')
69
                    ->canBeDisabled()
70
                    ->children()
71
                        ->scalarNode('transaction_naming')
72
                            ->defaultValue('route')
73
                            ->validate()
74
                                ->ifNotInArray(['route', 'controller', 'service'])
75
                                ->thenInvalid('Invalid transaction naming scheme "%s", must be "route", "controller" or "service".')
76
                            ->end()
77
                        ->end()
78
                        ->scalarNode('transaction_naming_service')->defaultNull()->end()
79
                        ->arrayNode('ignored_routes')
80
                            ->prototype('scalar')
81
                            ->end()
82
                            ->beforeNormalization()
83
                                ->ifTrue(function ($v) { return !\is_array($v); })
84
                                ->then(function ($v) { return (array) $v; })
85
                            ->end()
86
                        ->end()
87
                        ->arrayNode('ignored_paths')
88
                            ->prototype('scalar')
89
                            ->end()
90
                            ->beforeNormalization()
91
                                ->ifTrue(function ($v) { return !\is_array($v); })
92
                                ->then(function ($v) { return (array) $v; })
93
                            ->end()
94
                        ->end()
95
                        ->scalarNode('using_symfony_cache')->defaultFalse()->end()
96
                        ->booleanNode('instrument')
97
                            ->defaultFalse()
98
                        ->end()
99
                    ->end()
100
                ->end()
101
                ->arrayNode('monolog')
102
                    ->canBeEnabled()
103
                    ->fixXmlConfig('channel')
104
                    ->children()
105
                        ->arrayNode('channels')
106
                            ->prototype('scalar')->end()
107
                            ->defaultValue(['app'])
108
                        ->end()
109
                        ->scalarNode('level')->defaultValue(LogLevel::ERROR)->end()
110
                        ->scalarNode('service')->defaultValue('ekino.new_relic.monolog_handler')->end()
111
                    ->end()
112
                ->end()
113
            ->end()
114
        ;
115
116
        return $treeBuilder;
117
    }
118
}
119