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

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 84
Code Lines 79

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 79
nc 1
nop 0
dl 0
loc 84
rs 8.7169
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_commands')
57
                    ->defaultTrue()
58
                ->end()
59
                ->arrayNode('log_logs')
60
                    ->canBeEnabled()
61
                    ->fixXmlConfig('channel')
62
                    ->children()
63
                        ->arrayNode('channels')
64
                            ->prototype('scalar')->end()
65
                            ->defaultValue(['app'])
66
                        ->end()
67
                        ->scalarNode('level')->defaultValue(LogLevel::ERROR)->end()
68
                        ->scalarNode('service')->defaultValue('ekino.new_relic.logs_handler.real')->end()
69
                    ->end()
70
                ->end()
71
                ->scalarNode('transaction_naming')
72
                    ->defaultValue('route')
73
                    ->validate()
74
                        ->ifNotInArray(array('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
                ->arrayNode('ignored_commands')
96
                    ->prototype('scalar')
97
                    ->end()
98
                    ->beforeNormalization()
99
                        ->ifTrue(function ($v) { return !is_array($v); })
100
                        ->then(function ($v) { return (array) $v; })
101
                    ->end()
102
                ->end()
103
                ->scalarNode('using_symfony_cache')->defaultFalse()->end()
104
            ->end()
105
        ;
106
107
        return $treeBuilder;
108
    }
109
}
110