Completed
Push — master ( c1663c...4b2fbd )
by Petre
02:23
created

Configuration::getConfigTreeBuilder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 58
Code Lines 53

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 49
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 58
ccs 49
cts 49
cp 1
rs 9.639
cc 1
eloc 53
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) { return in_array($v, array('1', 'true', 'on')); })
43 4
                        ->end()
44 4
                    ->defaultValue(AirbrakeDefaultEnum::GLOBAL_EXCEPTION_INSTANCE)
45 4
                    ->end()
46 4
                ->booleanNode('global_error_and_exception_handler')
47 4
                    ->beforeNormalization()
48 4
                    ->ifString()
49
                        ->then(function($v) { return in_array($v, array('1', 'true', 'on')); })
50 4
                        ->end()
51 4
                    ->defaultValue(AirbrakeDefaultEnum::GLOBAL_ERROR_AND_EXCEPTION_HANDLER)
52 4
                    ->end()
53 4
                ->scalarNode('host')
54 4
                    ->defaultValue(AirbrakeDefaultEnum::HOST)
55 4
                    ->end()
56 4
                ->arrayNode('ignored_exceptions')
57 4
                    ->prototype('scalar')->end()
58 4
                    ->defaultValue(AirbrakeDefaultEnum::IGNORED_EXCEPTIONS)
59 4
                    ->end()
60 4
                ->scalarNode('root_directory')
61 4
                    ->defaultValue(AirbrakeDefaultEnum::ROOT_DIRECTORY)
62 4
                    ->end()
63 4
                ->scalarNode('environment')
64 4
                    ->defaultValue(AirbrakeDefaultEnum::ENVIRONMENT)
65 4
                    ->end()
66 4
                ->scalarNode('app_version')
67 4
                    ->defaultValue(AirbrakeDefaultEnum::APP_VERSION)
68 4
                    ->end()
69 4
                ->booleanNode('listener_enabled')
70 4
                    ->beforeNormalization()
71 4
                    ->ifString()
72
                        ->then(function($v) { return in_array($v, array('1', 'true', 'on')); })
73 4
                        ->end()
74 4
                    ->defaultValue(AirbrakeDefaultEnum::LISTNER_ENABLED)
75 4
                    ->end()
76 4
            ->end()
77
        ;
78
79 4
        return $treeBuilder;
80
    }
81
}
82