Configuration::getConfigTreeBuilder()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 54
Code Lines 47

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 54
rs 9.6716
cc 1
eloc 47
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 is part of the webuni/commonmark-bundle package.
5
 *
6
 * (c) Martin Hasoň <[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 Webuni\Bundle\CommonMarkBundle\DependencyInjection;
13
14
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
15
use Symfony\Component\Config\Definition\ConfigurationInterface;
16
17
class Configuration implements ConfigurationInterface
18
{
19
    public function getConfigTreeBuilder()
20
    {
21
        $builder = new TreeBuilder();
22
23
        $builder->root('webuni_commonmark', 'array')
24
            ->addDefaultsIfNotSet()
25
            ->children()
26
                ->scalarNode('default_converter')->defaultValue('default')->end()
27
                ->arrayNode('extensions')
28
                    ->addDefaultsIfNotSet()
29
                    ->children()
30
                        ->booleanNode('attributes')->defaultTrue()->end()
31
                        ->booleanNode('table')->defaultTrue()->end()
32
                    ->end()
33
                ->end()
34
                ->arrayNode('converters')
35
                    ->defaultValue(['default' => [
36
                        'converter'   => 'webuni_commonmark.converter',
37
                        'environment' => 'webuni_commonmark.default_environment',
38
                        'parser'      => 'webuni_commonmark.docparser',
39
                        'renderer'    => 'webuni_commonmark.htmlrenderer',
40
                        'config'      => [],
41
                        'extensions'  => [],
42
                    ]])
43
                    ->beforeNormalization()
44
                        ->always()
45
                        ->then(function ($v) {
46
                            return array_merge(['default' => null], $v);
47
                        })
48
                    ->end()
49
                    ->prototype('array')
50
                        ->addDefaultsIfNotSet()
51
                        ->children()
52
                            ->scalarNode('converter')->defaultValue('webuni_commonmark.converter')->end()
53
                            ->scalarNode('environment')->defaultValue('webuni_commonmark.default_environment')->end()
54
                            ->scalarNode('parser')->defaultValue('webuni_commonmark.docparser')->end()
55
                            ->scalarNode('renderer')->defaultValue('webuni_commonmark.htmlrenderer')->end()
56
                            ->arrayNode('config')
57
                                ->prototype('variable')
58
                                    ->defaultValue([])
59
                                ->end()
60
                            ->end()
61
                            ->arrayNode('extensions')
62
                                ->defaultValue([])
63
                                ->prototype('scalar')->end()
64
                            ->end()
65
                        ->end()
66
                    ->end()
67
                ->end()
68
            ->end()
69
        ;
70
71
        return $builder;
72
    }
73
}
74