Completed
Push — master ( 8fac40...c170a7 )
by Kamil
42:58
created

Configuration::addResourcesSection()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 90
Code Lines 87

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 90
rs 8.5454
c 0
b 0
f 0
cc 1
eloc 87
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\AdminApiBundle\DependencyInjection;
13
14
use Sylius\Bundle\AdminApiBundle\Form\Type\ClientType;
15
use Sylius\Bundle\AdminApiBundle\Model\AccessToken;
16
use Sylius\Bundle\AdminApiBundle\Model\AccessTokenInterface;
17
use Sylius\Bundle\AdminApiBundle\Model\AuthCode;
18
use Sylius\Bundle\AdminApiBundle\Model\AuthCodeInterface;
19
use Sylius\Bundle\AdminApiBundle\Model\Client;
20
use Sylius\Bundle\AdminApiBundle\Model\ClientInterface;
21
use Sylius\Bundle\AdminApiBundle\Model\RefreshToken;
22
use Sylius\Bundle\AdminApiBundle\Model\RefreshTokenInterface;
23
use Sylius\Bundle\AdminApiBundle\Model\UserInterface;
24
use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
25
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
26
use Sylius\Component\Resource\Factory\Factory;
27
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
28
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
29
use Symfony\Component\Config\Definition\ConfigurationInterface;
30
31
/**
32
 * @author Paweł Jędrzejewski <[email protected]>
33
 */
34
final class Configuration implements ConfigurationInterface
35
{
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function getConfigTreeBuilder()
40
    {
41
        $treeBuilder = new TreeBuilder();
42
        $rootNode = $treeBuilder->root('sylius_admin_api');
43
44
        $rootNode
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
     * @param ArrayNodeDefinition $node
56
     */
57
    private function addResourcesSection(ArrayNodeDefinition $node)
58
    {
59
        $node
60
            ->children()
61
                ->arrayNode('resources')
62
                    ->addDefaultsIfNotSet()
63
                    ->children()
64
                        ->arrayNode('api_user')
65
                            ->addDefaultsIfNotSet()
66
                            ->children()
67
                                ->variableNode('options')->end()
68
                                ->arrayNode('classes')
69
                                    ->addDefaultsIfNotSet()
70
                                    ->children()
71
                                        ->scalarNode('model')->isRequired()->cannotBeEmpty()->end()
72
                                        ->scalarNode('interface')->defaultValue(UserInterface::class)->cannotBeEmpty()->end()
73
                                    ->end()
74
                                ->end()
75
                            ->end()
76
                        ->end()
77
                        ->arrayNode('api_client')
78
                            ->addDefaultsIfNotSet()
79
                            ->children()
80
                                ->variableNode('options')->end()
81
                                ->arrayNode('classes')
82
                                    ->addDefaultsIfNotSet()
83
                                    ->children()
84
                                        ->scalarNode('model')->defaultValue(Client::class)->cannotBeEmpty()->end()
85
                                        ->scalarNode('interface')->defaultValue(ClientInterface::class)->cannotBeEmpty()->end()
86
                                        ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
87
                                        ->scalarNode('repository')->cannotBeEmpty()->end()
88
                                        ->scalarNode('factory')->defaultValue(Factory::class)->cannotBeEmpty()->end()
89
                                        ->scalarNode('form')->defaultValue(ClientType::class)->cannotBeEmpty()->end()
90
                                    ->end()
91
                                ->end()
92
                            ->end()
93
                        ->end()
94
                        ->arrayNode('api_access_token')
95
                            ->addDefaultsIfNotSet()
96
                            ->children()
97
                                ->variableNode('options')->end()
98
                                ->arrayNode('classes')
99
                                    ->addDefaultsIfNotSet()
100
                                    ->children()
101
                                        ->scalarNode('model')->defaultValue(AccessToken::class)->cannotBeEmpty()->end()
102
                                        ->scalarNode('interface')->defaultValue(AccessTokenInterface::class)->cannotBeEmpty()->end()
103
                                        ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
104
                                        ->scalarNode('repository')->cannotBeEmpty()->end()
105
                                        ->scalarNode('factory')->defaultValue(Factory::class)->cannotBeEmpty()->end()
106
                                    ->end()
107
                                ->end()
108
                            ->end()
109
                        ->end()
110
                        ->arrayNode('api_refresh_token')
111
                            ->addDefaultsIfNotSet()
112
                            ->children()
113
                                ->variableNode('options')->end()
114
                                ->arrayNode('classes')
115
                                    ->addDefaultsIfNotSet()
116
                                    ->children()
117
                                        ->scalarNode('model')->defaultValue(RefreshToken::class)->cannotBeEmpty()->end()
118
                                        ->scalarNode('interface')->defaultValue(RefreshTokenInterface::class)->cannotBeEmpty()->end()
119
                                        ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
120
                                        ->scalarNode('repository')->cannotBeEmpty()->end()
121
                                        ->scalarNode('factory')->defaultValue(Factory::class)->cannotBeEmpty()->end()
122
                                    ->end()
123
                                ->end()
124
                            ->end()
125
                        ->end()
126
                        ->arrayNode('api_auth_code')
127
                            ->addDefaultsIfNotSet()
128
                            ->children()
129
                                ->variableNode('options')->end()
130
                                ->arrayNode('classes')
131
                                    ->addDefaultsIfNotSet()
132
                                    ->children()
133
                                        ->scalarNode('model')->defaultValue(AuthCode::class)->cannotBeEmpty()->end()
134
                                        ->scalarNode('interface')->defaultValue(AuthCodeInterface::class)->cannotBeEmpty()->end()
135
                                        ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
136
                                        ->scalarNode('repository')->cannotBeEmpty()->end()
137
                                        ->scalarNode('factory')->defaultValue(Factory::class)->cannotBeEmpty()->end()
138
                                    ->end()
139
                                ->end()
140
                            ->end()
141
                        ->end()
142
                    ->end()
143
                ->end()
144
            ->end()
145
        ;
146
    }
147
}
148