Completed
Push — master ( 3081d8...0e5b16 )
by Ruud
43:38 queued 29:10
created

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 56

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 56
rs 8.9599
c 0
b 0
f 0
cc 2
nc 2
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
namespace Kunstmaan\NodeBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
6
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
7
use Symfony\Component\Config\Definition\ConfigurationInterface;
8
9
/**
10
 * This is the class that validates and merges configuration from your app/config files
11
 *
12
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
13
 */
14
class Configuration implements ConfigurationInterface
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public function getConfigTreeBuilder()
20
    {
21
        $treeBuilder = new TreeBuilder('kunstmaan_node');
22
        if (method_exists($treeBuilder, 'getRootNode')) {
23
            $rootNode = $treeBuilder->getRootNode();
24
        } else {
25
            // BC layer for symfony/config 4.1 and older
26
            $rootNode = $treeBuilder->root('kunstmaan_node');
27
        }
28
29
        /* @var ArrayNodeDefinition $pages */
30
        $rootNode
31
            ->children()
32
                ->arrayNode('pages')
33
                    ->prototype('array')
34
                        ->children()
35
                            ->scalarNode('name')->isRequired()->end()
36
                            ->scalarNode('search_type')->end()
37
                            ->booleanNode('structure_node')->end()
38
                            ->booleanNode('indexable')->end()
39
                            ->scalarNode('icon')->defaultNull()->end()
40
                            ->scalarNode('hidden_from_tree')->end()
41
                            ->booleanNode('is_homepage')->end()
42
                            ->arrayNode('allowed_children')
43
                                ->prototype('array')
44
                                    ->beforeNormalization()
45
                                        ->ifString()->then(function ($v) {
46
                                            return ['class' => $v];
47
                                        })
48
                                    ->end()
49
                                    ->children()
50
                                        ->scalarNode('class')->isRequired()->end()
51
                                        ->scalarNode('name')->end()
52
                                    ->end()
53
                                ->end()
54
                            ->end()
55
                        ->end()
56
                    ->end()
57
                ->end()
58
                ->scalarNode('publish_later_stepping')->defaultValue('15')->end()
59
                ->scalarNode('unpublish_later_stepping')->defaultValue('15')->end()
60
                ->booleanNode('show_add_homepage')->defaultTrue()->end()
61
                ->booleanNode('enable_export_page_template')->defaultFalse()->end()
62
                ->arrayNode('lock')
63
                    ->addDefaultsIfNotSet()
64
                    ->canBeEnabled()
65
                    ->children()
66
                        ->scalarNode('check_interval')->defaultValue(15)->end()
67
                        ->scalarNode('threshold')->defaultValue(35)->end()
68
                        ->booleanNode('enabled')->defaultFalse()->end()
69
                    ->end()
70
                ->end()
71
            ->end();
72
73
        return $treeBuilder;
74
    }
75
}
76