Completed
Push — master ( d88be7...2e7310 )
by WEBEWEB
01:23
created

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 64

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 64
rs 8.7853
c 0
b 0
f 0
cc 1
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 core-bundle package.
5
 *
6
 * (c) 2019 WEBEWEB
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 WBW\Bundle\CoreBundle\DependencyInjection;
13
14
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
15
use Symfony\Component\Config\Definition\ConfigurationInterface;
16
17
/**
18
 * Configuration.
19
 *
20
 * @author webeweb <https://github.com/webeweb/>
21
 * @package WBW\Bundle\CoreBundle\DependencyInjection
22
 */
23
class Configuration implements ConfigurationInterface {
24
25
    /**
26
     * {@inheritDoc}
27
     *
28
     * @see https://github.com/webeweb/core-bundle/blob/master/Tests/Fixtures/app/config/config_test.yml
29
     */
30
    public function getConfigTreeBuilder() {
31
32
        $assets  = ConfigurationHelper::loadYamlConfig(__DIR__, "assets");
33
        $plugins = $assets["assets"]["wbw.core.asset.core"]["plugins"];
34
35
        $treeBuilder = new TreeBuilder(WBWCoreExtension::EXTENSION_ALIAS);
36
37
        $rootNode = ConfigurationHelper::getRootNode($treeBuilder, WBWCoreExtension::EXTENSION_ALIAS);
38
        $rootNode
39
            ->children()
40
                ->booleanNode("commands")->defaultTrue()->info("Load commands")->end()
41
                ->booleanNode("event_listeners")->defaultTrue()->info("Load event listeners")->end()
42
                ->booleanNode("providers")->defaultTrue()->info("Load providers")->end()
43
                ->booleanNode("twig")->defaultTrue()->info("Load Twig extensions")->end()
44
                ->arrayNode("quote_providers")->addDefaultsIfNotSet()
45
                    ->children()
46
                        ->booleanNode("worlds_wisdom")->defaultFalse()->info("Load World's wisdom")->end()
47
                    ->end()
48
                ->end()
49
                ->booleanNode("security_event_listener")->defaultFalse()->info("Load Security event listener")->end()
50
                ->arrayNode("plugins")->info("Core plug-ins")
51
                    ->prototype("scalar")
52
                        ->validate()
53
                            ->ifNotInArray(array_keys($plugins))
54
                            ->thenInvalid("The Core plug-in %s is not supported. Please choose one of " . json_encode(array_keys($plugins)))
55
                        ->end()
56
                    ->end()
57
                ->end()
58
                ->arrayNode("locales")->addDefaultsIfNotSet()
59
                    ->children()
60
                        ->variableNode("jquery_select2")->defaultValue("en")->info("jQuery Select2 locale")
61
                            ->validate()
62
                                ->ifNotInArray($plugins["jquery_select2"]["locales"])
63
                                ->thenInvalid("The jQuery Select2 locale %s is not supported. Please choose one of " . json_encode($plugins["jquery_select2"]["locales"]))
64
                            ->end()
65
                        ->end()
66
                    ->end()
67
                ->end()
68
                ->arrayNode("themes")->addDefaultsIfNotSet()
69
                    ->children()
70
                        ->variableNode("syntax_highlighter")->defaultValue("Default")->info("SyntaxHighlighter theme")
71
                            ->validate()
72
                                ->ifNotInArray($plugins["syntax_highlighter"]["themes"])
73
                                ->thenInvalid("The SyntaxHighlighter theme %s is not supported. Please choose one of " . json_encode($plugins["syntax_highlighter"]["themes"]))
74
                            ->end()
75
                        ->end()
76
                    ->end()
77
                ->end()
78
                ->arrayNode("brushes")
79
                    ->children()
80
                        ->arrayNode("syntax_highlighter")->info("SyntaxHighlighter brushes")
81
                            ->prototype("scalar")
82
                                ->validate()
83
                                    ->ifNotInArray($plugins["syntax_highlighter"]["brushes"])
84
                                    ->thenInvalid("The SyntaxHighlighter brush %s is not supported. Please choose one of " . json_encode($plugins["syntax_highlighter"]["brushes"]))
85
                                ->end()
86
                            ->end()
87
                        ->end()
88
                    ->end()
89
                ->end()
90
            ->end();
91
92
        return $treeBuilder;
93
    }
94
}
95