Completed
Push — symfony3 ( ec9673...e0eba1 )
by Kamil
18:54
created

Configuration::addResourcesSection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 74
Code Lines 71

Duplication

Lines 0
Ratio 0 %

Importance

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