Completed
Push — master ( 23f69a...13261c )
by Nikola
03:25
created

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 5
Paths 1

Size

Total Lines 73
Code Lines 60

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 53
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 73
ccs 53
cts 53
cp 1
rs 8.5021
c 1
b 0
f 0
cc 5
eloc 60
nc 1
nop 0
crap 5

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
 * This file is part of the  TraitorBundle, an RunOpenCode project.
4
 *
5
 * (c) 2017 RunOpenCode
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace RunOpenCode\Bundle\Traitor\DependencyInjection;
11
12
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
13
use Symfony\Component\Config\Definition\ConfigurationInterface;
14
15
class Configuration implements ConfigurationInterface
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20 2
    public function getConfigTreeBuilder()
21
    {
22 2
        $treeBuilder = new TreeBuilder();
23
24 2
        $rootNode = $treeBuilder->root('runopencode_traitor');
25
26
        $rootNode
27 2
            ->addDefaultsIfNotSet()
28 2
            ->children()
29 2
                ->booleanNode('use_common_traits')
30 2
                    ->defaultFalse()
31 2
                    ->info('For sake of productivity, some of the common Symfony and vendor traits, as well as traits from this library, can be automatically added to "inject" definition.')
32 2
                ->end()
33 2
                ->arrayNode('inject')
34 2
                    ->useAttributeAsKey('trait')
35 2
                    ->prototype('array')
36 2
                        ->validate()
37 2
                            ->ifTrue(function($value) {
38
39
                                if (!is_array($value) || 2 !== count($value)) {
40
                                    return true;
41
                                }
42
43
                                if (!is_string($value[0])) {
44
                                    return true;
45
                                }
46
47
                                if (!is_array($value[1])) {
48
                                    return true;
49
                                }
50
51
                                return false;
52 2
                            })
53 2
                            ->thenInvalid('Expected proper setter injection definition.')
54 2
                        ->end()
55 2
                        ->prototype('variable')
56 2
                        ->end()
57 2
                    ->end()
58 2
                ->end()
59 2
                ->arrayNode('filters')
60 2
                    ->info('Analyse services for injection which matches filter criteria.')
61 2
                    ->children()
62 2
                        ->arrayNode('tags')
63 2
                            ->prototype('scalar')
64 2
                            ->end()
65 2
                        ->end()
66 2
                        ->arrayNode('namespaces')
67 2
                            ->prototype('scalar')
68 2
                            ->end()
69 2
                        ->end()
70 2
                    ->end()
71 2
                ->end()
72 2
                ->arrayNode('exclude')
73 2
                    ->info('Exclude services from injection which matches filter criteria.')
74 2
                    ->children()
75 2
                        ->arrayNode('services')
76 2
                            ->prototype('scalar')
77 2
                            ->end()
78 2
                        ->end()
79 2
                        ->arrayNode('namespaces')
80 2
                            ->prototype('scalar')
81 2
                            ->end()
82 2
                        ->end()
83 2
                        ->arrayNode('classes')
84 2
                            ->prototype('scalar')
85 2
                            ->end()
86 2
                        ->end()
87 2
                    ->end()
88 2
                ->end()
89 2
            ->end();
90
91 2
        return $treeBuilder;
92
    }
93
}
94