Configuration::getConfigTreeBuilder()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 55
Code Lines 45

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 2
Metric Value
c 3
b 0
f 2
dl 0
loc 55
rs 9.7692
cc 1
eloc 45
nc 1
nop 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 the Tadcka package.
5
 *
6
 * (c) Tadas Gliaubicas <[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 Tadcka\Bundle\RoutingBundle\DependencyInjection;
13
14
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
15
use Symfony\Component\Config\Definition\ConfigurationInterface;
16
17
/**
18
 * @author Tadas Gliaubicas <[email protected]>
19
 *
20
 * @since 7/1/14 11:09 PM
21
 */
22
class Configuration implements ConfigurationInterface
23
{
24
    /**
25
     * {@inheritDoc}
26
     */
27
    public function getConfigTreeBuilder()
28
    {
29
        $treeBuilder = new TreeBuilder();
30
        $rootNode = $treeBuilder->root('tadcka_routing');
31
32
        $rootNode
33
            ->children()
34
                ->scalarNode('db_driver')->cannotBeOverwritten()->isRequired()->end()
35
                ->scalarNode('route_manager')->defaultValue('tadcka_routing.manager.route.default')
36
                    ->cannotBeEmpty()->end()
37
                ->scalarNode('redirect_route_manager')->defaultValue('tadcka_routing.manager.redirect_route.default')
38
                    ->cannotBeEmpty()->end()
39
40
                ->arrayNode('class')->isRequired()
41
                    ->children()
42
                        ->arrayNode('model')->isRequired()
43
                            ->children()
44
                                ->scalarNode('route')->isRequired()->end()
45
                                ->scalarNode('redirect_route')->isRequired()->end()
46
                            ->end()
47
                        ->end()
48
                    ->end()
49
                ->end()
50
51
                ->arrayNode('chain_router')->addDefaultsIfNotSet()
52
                    ->children()
53
                        ->booleanNode('enabled')->defaultFalse()->end()
54
                    ->end()
55
                ->end()
56
57
                ->arrayNode('dynamic_router')->addDefaultsIfNotSet()
58
                    ->children()
59
                        ->integerNode('priority')->defaultValue(0)->end()
60
                    ->end()
61
                ->end()
62
63
                ->arrayNode('router')->addDefaultsIfNotSet()
64
                    ->children()
65
                        ->integerNode('priority')->defaultValue(0)->end()
66
                    ->end()
67
                ->end()
68
69
                ->arrayNode('locales')
70
                    ->beforeNormalization()
71
                        ->ifString()
72
                        ->then(function($value) { return preg_split('/\s*,\s*/', $value); })
73
                    ->end()
74
                    ->requiresAtLeastOneElement()
75
                    ->prototype('scalar')->end()
76
                ->end()
77
78
            ->end();
79
80
        return $treeBuilder;
81
    }
82
}
83