Configuration::getConfigTreeBuilder()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 165

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 165
rs 8
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 Superdesk Web Publisher Bridge Bundle.
5
 *
6
 * Copyright 2016 Sourcefabric z.ú. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2016 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Bundle\BridgeBundle\DependencyInjection;
16
17
use SWP\Bundle\BridgeBundle\Doctrine\ORM\PackageRepository;
18
use SWP\Bundle\StorageBundle\Doctrine\ORM\EntityRepository;
19
use SWP\Component\Bridge\Model\Event;
20
use SWP\Component\Bridge\Model\Event\Date;
21
use SWP\Component\Bridge\Model\Event\DateInterface;
22
use SWP\Component\Bridge\Model\Event\Location;
23
use SWP\Component\Bridge\Model\Event\LocationInterface;
24
use SWP\Component\Bridge\Model\EventInterface;
25
use SWP\Component\Bridge\Model\ExternalData;
26
use SWP\Component\Bridge\Model\ExternalDataInterface;
27
use SWP\Component\Bridge\Model\Group;
28
use SWP\Component\Bridge\Model\GroupInterface;
29
use SWP\Component\Bridge\Model\Item;
30
use SWP\Component\Bridge\Model\ItemInterface;
31
use SWP\Component\Bridge\Model\Package;
32
use SWP\Component\Bridge\Model\PackageInterface;
33
use SWP\Component\Bridge\Model\Rendition;
34
use SWP\Component\Bridge\Model\RenditionInterface;
35
use SWP\Component\Storage\Factory\Factory;
36
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
37
use Symfony\Component\Config\Definition\ConfigurationInterface;
38
39
/**
40
 * This is the class that validates and merges configuration from your app/config files.
41
 *
42
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
43
 */
44
class Configuration implements ConfigurationInterface
45
{
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function getConfigTreeBuilder()
50
    {
51
        $treeBuilder = new TreeBuilder('swp_bridge', 'array');
52
        $rootNode = $treeBuilder->getRootNode();
53
54
        $rootNode
55
            ->children()
56
                ->arrayNode('persistence')
57
                    ->addDefaultsIfNotSet()
58
                    ->children()
59
                        ->arrayNode('orm')
60
                            ->addDefaultsIfNotSet()
61
                            ->canBeEnabled()
62
                            ->children()
63
                                ->arrayNode('classes')
64
                                    ->addDefaultsIfNotSet()
65
                                    ->children()
66
                                        ->arrayNode('package')
67
                                            ->addDefaultsIfNotSet()
68
                                            ->children()
69
                                                ->scalarNode('model')->cannotBeEmpty()->defaultValue(Package::class)->end()
70
                                                ->scalarNode('repository')->defaultValue(PackageRepository::class)->end()
71
                                                ->scalarNode('interface')->defaultValue(PackageInterface::class)->end()
72
                                                ->scalarNode('factory')->defaultValue(Factory::class)->end()
73
                                                ->scalarNode('object_manager_name')->defaultValue(null)->end()
74
                                            ->end()
75
                                        ->end()
76
                                        ->arrayNode('item')
77
                                            ->addDefaultsIfNotSet()
78
                                            ->children()
79
                                                ->scalarNode('model')->cannotBeEmpty()->defaultValue(Item::class)->end()
80
                                                ->scalarNode('repository')->defaultValue(EntityRepository::class)->end()
81
                                                ->scalarNode('interface')->defaultValue(ItemInterface::class)->end()
82
                                                ->scalarNode('factory')->defaultValue(Factory::class)->end()
83
                                                ->scalarNode('object_manager_name')->defaultValue(null)->end()
84
                                            ->end()
85
                                        ->end()
86
                                        ->arrayNode('rendition')
87
                                            ->addDefaultsIfNotSet()
88
                                            ->children()
89
                                                ->scalarNode('model')->cannotBeEmpty()->defaultValue(Rendition::class)->end()
90
                                                ->scalarNode('repository')->defaultValue(EntityRepository::class)->end()
91
                                                ->scalarNode('interface')->defaultValue(RenditionInterface::class)->end()
92
                                                ->scalarNode('factory')->defaultValue(Factory::class)->end()
93
                                                ->scalarNode('object_manager_name')->defaultValue(null)->end()
94
                                            ->end()
95
                                        ->end()
96
                                        ->arrayNode('external_data')
97
                                            ->addDefaultsIfNotSet()
98
                                            ->children()
99
                                                ->scalarNode('model')->cannotBeEmpty()->defaultValue(ExternalData::class)->end()
100
                                                ->scalarNode('repository')->defaultValue(EntityRepository::class)->end()
101
                                                ->scalarNode('interface')->defaultValue(ExternalDataInterface::class)->end()
102
                                                ->scalarNode('factory')->defaultValue(Factory::class)->end()
103
                                                ->scalarNode('object_manager_name')->defaultValue(null)->end()
104
                                            ->end()
105
                                        ->end()
106
                                        ->arrayNode('group')
107
                                            ->addDefaultsIfNotSet()
108
                                            ->children()
109
                                                ->scalarNode('model')->cannotBeEmpty()->defaultValue(Group::class)->end()
110
                                                ->scalarNode('repository')->defaultValue(EntityRepository::class)->end()
111
                                                ->scalarNode('interface')->defaultValue(GroupInterface::class)->end()
112
                                                ->scalarNode('factory')->defaultValue(Factory::class)->end()
113
                                                ->scalarNode('object_manager_name')->defaultValue(null)->end()
114
                                            ->end()
115
                                        ->end()
116
                                        ->arrayNode('event')
117
                                            ->addDefaultsIfNotSet()
118
                                            ->children()
119
                                                ->scalarNode('model')->cannotBeEmpty()->defaultValue(Event::class)->end()
120
                                                ->scalarNode('repository')->defaultValue(EntityRepository::class)->end()
121
                                                ->scalarNode('factory')->defaultValue(Factory::class)->end()
122
                                                ->scalarNode('interface')->defaultValue(EventInterface::class)->end()
123
                                                ->scalarNode('object_manager_name')->defaultValue(null)->end()
124
                                            ->end()
125
                                        ->end()
126
                                        ->arrayNode('event_date')
127
                                            ->addDefaultsIfNotSet()
128
                                            ->children()
129
                                                ->scalarNode('model')->cannotBeEmpty()->defaultValue(Date::class)->end()
130
                                                ->scalarNode('repository')->defaultValue(EntityRepository::class)->end()
131
                                                ->scalarNode('factory')->defaultValue(Factory::class)->end()
132
                                                ->scalarNode('interface')->defaultValue(DateInterface::class)->end()
133
                                                ->scalarNode('object_manager_name')->defaultValue(null)->end()
134
                                            ->end()
135
                                        ->end()
136
                                        ->arrayNode('event_location')
137
                                            ->addDefaultsIfNotSet()
138
                                            ->children()
139
                                                ->scalarNode('model')->cannotBeEmpty()->defaultValue(Location::class)->end()
140
                                                ->scalarNode('repository')->defaultValue(EntityRepository::class)->end()
141
                                                ->scalarNode('factory')->defaultValue(Factory::class)->end()
142
                                                ->scalarNode('interface')->defaultValue(LocationInterface::class)->end()
143
                                                ->scalarNode('object_manager_name')->defaultValue(null)->end()
144
                                            ->end()
145
                                        ->end()
146
                                        ->arrayNode('event_occur_status')
147
                                            ->addDefaultsIfNotSet()
148
                                            ->children()
149
                                                ->scalarNode('model')->cannotBeEmpty()->defaultValue(Event\OccurStatus::class)->end()
150
                                                ->scalarNode('repository')->defaultValue(EntityRepository::class)->end()
151
                                                ->scalarNode('factory')->defaultValue(Factory::class)->end()
152
                                                ->scalarNode('interface')->defaultValue(Event\OccurStatusInterface::class)->end()
153
                                                ->scalarNode('object_manager_name')->defaultValue(null)->end()
154
                                            ->end()
155
                                        ->end()
156
                                        ->arrayNode('event_category')
157
                                            ->addDefaultsIfNotSet()
158
                                            ->children()
159
                                                ->scalarNode('model')->cannotBeEmpty()->defaultValue(Event\Category::class)->end()
160
                                                ->scalarNode('repository')->defaultValue(EntityRepository::class)->end()
161
                                                ->scalarNode('factory')->defaultValue(Factory::class)->end()
162
                                                ->scalarNode('interface')->defaultValue(Event\CategoryInterface::class)->end()
163
                                                ->scalarNode('object_manager_name')->defaultValue(null)->end()
164
                                            ->end()
165
                                        ->end()
166
                                    ->end()
167
                                ->end()
168
                            ->end()
169
                        ->end() // orm
170
                    ->end()
171
                ->end()
172
                ->arrayNode('api')
173
                    ->children()
174
                        ->scalarNode('host')
175
                            ->info('Hostname of the Content API.')
176
                            ->isRequired()
177
                            ->cannotBeEmpty()
178
                        ->end()
179
                        ->integerNode('port')
180
                            ->info('Port of the Content API.')
181
                            ->defaultValue(80)
182
                        ->end()
183
                        ->enumNode('protocol')
184
                            ->info('Protocol which will be used for connection to the Content Api.')
185
                            ->values(['http', 'https'])
186
                            ->defaultValue('https')
187
                        ->end()
188
                    ->end()
189
                ->end()
190
                ->arrayNode('auth')
191
                    ->children()
192
                        ->scalarNode('client_id')
193
                            ->info('Client ID for OAuth2 authentication for the Content Api.')
194
                            ->isRequired()
195
                            ->cannotBeEmpty()
196
                        ->end()
197
                        ->scalarNode('username')
198
                            ->info('Username for OAuth2 authentication for the Content Api.')
199
                            ->isRequired()
200
                            ->cannotBeEmpty()
201
                        ->end()
202
                        ->scalarNode('password')
203
                            ->info('Password for OAuth2 authentication for the Content Api.')
204
                            ->isRequired()
205
                            ->cannotBeEmpty()
206
                        ->end()
207
                    ->end()
208
                ->end()
209
                ->variableNode('options')->end()
210
            ->end();
211
212
        return $treeBuilder;
213
    }
214
}
215