Completed
Push — master ( 59db0f...abafe8 )
by Kamil
18:55
created

Configuration::addResourcesSection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 74
Code Lines 71

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 74
rs 9.0335
cc 1
eloc 71
nc 1
nop 1

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 Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
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 Sylius\Bundle\TaxonomyBundle\DependencyInjection;
13
14
use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
15
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
16
use Sylius\Bundle\TaxonomyBundle\Form\Type\TaxonTranslationType;
17
use Sylius\Bundle\TaxonomyBundle\Form\Type\TaxonType;
18
use Sylius\Component\Resource\Factory\Factory;
19
use Sylius\Component\Taxonomy\Model\Taxon;
20
use Sylius\Component\Taxonomy\Model\TaxonInterface;
21
use Sylius\Component\Taxonomy\Model\TaxonTranslation;
22
use Sylius\Component\Taxonomy\Model\TaxonTranslationInterface;
23
use Sylius\Component\Translation\Factory\TranslatableFactory;
24
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
25
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
26
use Symfony\Component\Config\Definition\ConfigurationInterface;
27
28
/**
29
 * This class contains the configuration information for the bundle.
30
 *
31
 * This information is solely responsible for how the different configuration
32
 * sections are normalized, and merged.
33
 *
34
 * @author Paweł Jędrzejewski <[email protected]>
35
 */
36
class Configuration implements ConfigurationInterface
37
{
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function getConfigTreeBuilder()
42
    {
43
        $treeBuilder = new TreeBuilder();
44
        $rootNode = $treeBuilder->root('sylius_taxonomy');
45
46
        $rootNode
47
            ->addDefaultsIfNotSet()
48
            ->children()
49
                ->scalarNode('driver')->defaultValue(SyliusResourceBundle::DRIVER_DOCTRINE_ORM)->end()
50
            ->end();
51
52
        $this->addResourcesSection($rootNode);
53
54
        return $treeBuilder;
55
    }
56
57
    /**
58
     * @param ArrayNodeDefinition $node
59
     */
60
    private function addResourcesSection(ArrayNodeDefinition $node)
61
    {
62
        $node
63
            ->children()
64
                ->arrayNode('resources')
65
                    ->addDefaultsIfNotSet()
66
                    ->children()
67
                        ->arrayNode('taxon')
68
                            ->addDefaultsIfNotSet()
69
                            ->children()
70
                                ->variableNode('options')->end()
71
                                ->arrayNode('classes')
72
                                    ->addDefaultsIfNotSet()
73
                                    ->children()
74
                                        ->scalarNode('model')->defaultValue(Taxon::class)->cannotBeEmpty()->end()
75
                                        ->scalarNode('interface')->defaultValue(TaxonInterface::class)->cannotBeEmpty()->end()
76
                                        ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
77
                                        ->scalarNode('repository')->cannotBeEmpty()->end()
78
                                        ->scalarNode('factory')->defaultValue(TranslatableFactory::class)->end()
79
                                        ->arrayNode('form')
80
                                            ->addDefaultsIfNotSet()
81
                                            ->children()
82
                                                ->scalarNode('default')->defaultValue(TaxonType::class)->cannotBeEmpty()->end()
83
                                            ->end()
84
                                        ->end()
85
                                    ->end()
86
                                ->end()
87
                                ->arrayNode('validation_groups')
88
                                    ->addDefaultsIfNotSet()
89
                                    ->children()
90
                                        ->arrayNode('default')
91
                                            ->prototype('scalar')->end()
92
                                            ->defaultValue(['sylius'])
93
                                        ->end()
94
                                    ->end()
95
                                ->end()
96
                                ->arrayNode('translation')
97
                                    ->addDefaultsIfNotSet()
98
                                    ->children()
99
                                        ->variableNode('options')->end()
100
                                        ->arrayNode('classes')
101
                                            ->addDefaultsIfNotSet()
102
                                            ->children()
103
                                                ->scalarNode('model')->defaultValue(TaxonTranslation::class)->cannotBeEmpty()->end()
104
                                                ->scalarNode('interface')->defaultValue(TaxonTranslationInterface::class)->cannotBeEmpty()->end()
105
                                                ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
106
                                                ->scalarNode('repository')->cannotBeEmpty()->end()
107
                                                ->scalarNode('factory')->defaultValue(Factory::class)->end()
108
                                                ->arrayNode('form')
109
                                                    ->addDefaultsIfNotSet()
110
                                                    ->children()
111
                                                        ->scalarNode('default')->defaultValue(TaxonTranslationType::class)->cannotBeEmpty()->end()
112
                                                    ->end()
113
                                                ->end()
114
                                            ->end()
115
                                        ->end()
116
                                        ->arrayNode('validation_groups')
117
                                            ->addDefaultsIfNotSet()
118
                                            ->children()
119
                                                ->arrayNode('default')
120
                                                    ->prototype('scalar')->end()
121
                                                    ->defaultValue(['sylius'])
122
                                                ->end()
123
                                            ->end()
124
                                        ->end()
125
                                    ->end()
126
                                ->end()
127
                            ->end()
128
                        ->end()
129
                    ->end()
130
                ->end()
131
            ->end()
132
        ;
133
    }
134
}
135