Configuration::getConfigTreeBuilder()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 64
Code Lines 56

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 53
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 64
ccs 53
cts 53
cp 1
rs 9.3956
c 2
b 0
f 0
cc 1
eloc 56
nc 1
nop 0
crap 1

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
declare(strict_types = 1);
3
4
namespace SM\AirbrakeBundle\DependencyInjection;
5
6
use SM\AirbrakeBundle\Enum\AirbrakeDefaultEnum;
7
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
8
use Symfony\Component\Config\Definition\ConfigurationInterface;
9
10
/**
11
 * Sets up the configuration parameters of the Airbrake bundle.
12
 *
13
 * @package SM\AirbrakeBundle\DependencyInjection
14
 * @author  Petre Pătrașc <[email protected]>
15
 */
16
class Configuration implements ConfigurationInterface
17
{
18
    /**
19
     * Generates the configuration tree builder.
20
     *
21
     * @return TreeBuilder
22
     */
23 4
    public function getConfigTreeBuilder(): TreeBuilder
24
    {
25 4
        $treeBuilder = new TreeBuilder();
26 4
        $rootNode    = $treeBuilder->root('sm_airbrake');
27
28
        $rootNode
29 4
            ->children()
30 4
                ->scalarNode('project_id')
31 4
                    ->defaultValue(AirbrakeDefaultEnum::PROJECT_ID)
32 4
                    ->end()
33 4
                ->scalarNode('project_key')
34 4
                    ->defaultValue(AirbrakeDefaultEnum::PROJECT_KEY)
35 4
                    ->end()
36 4
                ->scalarNode('http_client')
37 4
                    ->defaultValue(AirbrakeDefaultEnum::HTTP_CLIENT)
38 4
                    ->end()
39 4
                ->booleanNode('global_exception_instance')
40 4
                    ->beforeNormalization()
41 4
                    ->ifString()
42
                        ->then(function ($v) {
43
                            return in_array($v, array('1', 'true', 'on'));
44 4
                        })
45 4
                        ->end()
46 4
                    ->defaultValue(AirbrakeDefaultEnum::GLOBAL_EXCEPTION_INSTANCE)
47 4
                    ->end()
48 4
                ->booleanNode('global_error_and_exception_handler')
49 4
                    ->beforeNormalization()
50 4
                    ->ifString()
51
                        ->then(function ($v) {
52
                            return in_array($v, array('1', 'true', 'on'));
53 4
                        })
54 4
                        ->end()
55 4
                    ->defaultValue(AirbrakeDefaultEnum::GLOBAL_ERROR_AND_EXCEPTION_HANDLER)
56 4
                    ->end()
57 4
                ->scalarNode('host')
58 4
                    ->defaultValue(AirbrakeDefaultEnum::HOST)
59 4
                    ->end()
60 4
                ->arrayNode('ignored_exceptions')
61 4
                    ->prototype('scalar')->end()
62 4
                    ->defaultValue(AirbrakeDefaultEnum::IGNORED_EXCEPTIONS)
63 4
                    ->end()
64 4
                ->scalarNode('root_directory')
65 4
                    ->defaultValue(AirbrakeDefaultEnum::ROOT_DIRECTORY)
66 4
                    ->end()
67 4
                ->scalarNode('environment')
68 4
                    ->defaultValue(AirbrakeDefaultEnum::ENVIRONMENT)
69 4
                    ->end()
70 4
                ->scalarNode('app_version')
71 4
                    ->defaultValue(AirbrakeDefaultEnum::APP_VERSION)
72 4
                    ->end()
73 4
                ->booleanNode('listener_enabled')
74 4
                    ->beforeNormalization()
75 4
                    ->ifString()
76 4
                        ->then(function ($v) {
77
                            return in_array($v, array('1', 'true', 'on'));
78 4
                        })
79 4
                        ->end()
80 4
                    ->defaultValue(AirbrakeDefaultEnum::LISTNER_ENABLED)
81 4
                    ->end()
82 4
            ->end()
83
        ;
84
85 4
        return $treeBuilder;
86
    }
87
}
88