Completed
Pull Request — master (#145)
by Jérémy
02:42
created

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 87
Code Lines 82

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 82
nc 1
nop 0
dl 0
loc 87
rs 8.6296
c 0
b 0
f 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
/*
4
 * This file is part of Ekino New Relic bundle.
5
 *
6
 * (c) Ekino - Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ekino\Bundle\NewRelicBundle\DependencyInjection;
13
14
use Psr\Log\LogLevel;
15
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
16
use Symfony\Component\Config\Definition\ConfigurationInterface;
17
18
19
class Configuration implements ConfigurationInterface
20
{
21
    /**
22
     * {@inheritDoc}
23
     */
24
    public function getConfigTreeBuilder()
25
    {
26
        $treeBuilder = new TreeBuilder();
27
        $rootNode = $treeBuilder->root('ekino_new_relic');
28
29
        $rootNode
30
            ->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

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