Completed
Push — master ( 0729b3...dbaae6 )
by Kamil
18:26
created

Configuration::addResourcesSection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 75
Code Lines 72

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 75
rs 9
cc 1
eloc 72
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\AssociationBundle\DependencyInjection;
13
14
use Sylius\Bundle\AssociationBundle\Form\Type\AssociationType;
15
use Sylius\Bundle\AssociationBundle\Form\Type\AssociationTypeType;
16
use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
17
use Sylius\Bundle\ResourceBundle\Form\Type\ResourceChoiceType;
18
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
19
use Sylius\Component\Association\Model\AssociationType as AssociationTypeModel;
20
use Sylius\Component\Resource\Factory\Factory;
21
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
22
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
23
use Symfony\Component\Config\Definition\ConfigurationInterface;
24
25
/**
26
 * @author Łukasz Chruściel <[email protected]>
27
 */
28
class Configuration implements ConfigurationInterface
29
{
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function getConfigTreeBuilder()
34
    {
35
        $treeBuilder = new TreeBuilder();
36
        $rootNode = $treeBuilder->root('sylius_association');
37
38
        $rootNode
39
            ->addDefaultsIfNotSet()
40
            ->children()
41
                ->scalarNode('driver')->defaultValue(SyliusResourceBundle::DRIVER_DOCTRINE_ORM)->end()
42
            ->end()
43
        ;
44
45
        $this->addResourcesSection($rootNode);
46
47
        return $treeBuilder;
48
    }
49
50
    /**
51
     * @param ArrayNodeDefinition $node
52
     */
53
    private function addResourcesSection(ArrayNodeDefinition $node)
54
    {
55
        $node
56
            ->children()
57
                ->arrayNode('resources')
58
                    ->useAttributeAsKey('name')
59
                    ->prototype('array')
60
                        ->children()
61
                            ->scalarNode('subject')->isRequired()->end()
62
                            ->arrayNode('association')
63
                                ->isRequired()
64
                                ->addDefaultsIfNotSet()
65
                                ->children()
66
                                    ->arrayNode('classes')
67
                                        ->addDefaultsIfNotSet()
68
                                        ->children()
69
                                            ->scalarNode('model')->isRequired()->cannotBeEmpty()->end()
70
                                            ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
71
                                            ->scalarNode('factory')->defaultValue(Factory::class)->cannotBeEmpty()->end()
72
                                            ->scalarNode('repository')->cannotBeEmpty()->end()
73
                                            ->arrayNode('form')
74
                                                ->addDefaultsIfNotSet()
75
                                                ->children()
76
                                                    ->scalarNode('default')->defaultValue(AssociationType::class)->cannotBeEmpty()->end()
77
                                                ->end()
78
                                            ->end()
79
                                        ->end()
80
                                    ->end()
81
                                    ->arrayNode('validation_groups')
82
                                        ->addDefaultsIfNotSet()
83
                                        ->children()
84
                                            ->arrayNode('default')
85
                                                ->prototype('scalar')->end()
86
                                                ->defaultValue(array('sylius'))
87
                                            ->end()
88
                                        ->end()
89
                                    ->end()
90
                                ->end()
91
                            ->end()
92
                            ->arrayNode('association_type')
93
                                ->addDefaultsIfNotSet()
94
                                ->children()
95
                                    ->arrayNode('classes')
96
                                        ->addDefaultsIfNotSet()
97
                                        ->children()
98
                                            ->scalarNode('model')->defaultValue(AssociationTypeModel::class)->cannotBeEmpty()->end()
99
                                            ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
100
                                            ->scalarNode('factory')->defaultValue(Factory::class)->cannotBeEmpty()->end()
101
                                            ->scalarNode('repository')->cannotBeEmpty()->end()
102
                                            ->arrayNode('form')
103
                                                ->addDefaultsIfNotSet()
104
                                                ->children()
105
                                                    ->scalarNode('default')->defaultValue(AssociationTypeType::class)->cannotBeEmpty()->end()
106
                                                    ->scalarNode('choice')->defaultValue(ResourceChoiceType::class)->cannotBeEmpty()->end()
107
                                                ->end()
108
                                            ->end()
109
                                        ->end()
110
                                    ->end()
111
                                    ->arrayNode('validation_groups')
112
                                        ->addDefaultsIfNotSet()
113
                                        ->children()
114
                                            ->arrayNode('default')
115
                                                ->prototype('scalar')->end()
116
                                                ->defaultValue(array('sylius'))
117
                                            ->end()
118
                                        ->end()
119
                                    ->end()
120
                                ->end()
121
                            ->end()
122
                        ->end()
123
                    ->end()
124
                ->end()
125
            ->end()
126
        ;
127
    }
128
}
129