Completed
Pull Request — develop (#42)
by A.
02:36
created

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 88
Code Lines 77

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 3
Metric Value
c 5
b 0
f 3
dl 0
loc 88
rs 8.6012
cc 1
eloc 77
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
 * Copyright 2015 SURFnet B.V.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace OpenConext\ProfileBundle\DependencyInjection;
20
21
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
22
use Symfony\Component\Config\Definition\ConfigurationInterface;
23
24
class Configuration implements ConfigurationInterface
25
{
26
    public function getConfigTreeBuilder()
27
    {
28
        $treeBuilder = new TreeBuilder();
29
        $rootNode = $treeBuilder->root('open_conext_profile');
30
31
        $rootNode
32
            ->children()
33
                ->scalarNode('engine_block_entity_id')
34
                    ->info('The EntityID of EngineBlock')
35
                    ->isRequired()
36
                    ->validate()
37
                        ->ifTrue(function ($entityId) {
38
                            return !is_string($entityId);
39
                        })
40
                        ->thenInvalid('EngineBlock EntityID should be a string')
41
                    ->end()
42
                ->end()
43
                ->arrayNode('locales')
44
                    ->info('The available application locales')
45
                    ->isRequired()
46
                    ->prototype('scalar')
47
                        ->validate()
48
                            ->ifTrue(function ($locale) {
49
                                return !is_string($locale);
50
                            })
51
                            ->thenInvalid('Available application locales should be strings')
52
                        ->end()
53
                    ->end()
54
                ->end()
55
                ->scalarNode('default_locale')
56
                    ->info('The default application locale')
57
                    ->isRequired()
58
                    ->validate()
59
                        ->ifTrue(function ($locale) {
60
                            return !is_string($locale);
61
                        })
62
                        ->thenInvalid('Default application locale should be a string')
63
                    ->end()
64
                ->end()
65
                ->scalarNode('locale_cookie_domain')
66
                    ->info('The domain for which the locale cookie is set')
67
                    ->isRequired()
68
                    ->validate()
69
                        ->ifTrue(function ($domain) {
70
                            return !is_string($domain);
71
                        })
72
                        ->thenInvalid('Locale cookie domain should be a string')
73
                    ->end()
74
                ->end()
75
                ->scalarNode('locale_cookie_key')
76
                    ->info('The key for which the locale cookie value is set')
77
                    ->isRequired()
78
                    ->validate()
79
                        ->ifTrue(function ($key) {
80
                            return !is_string($key);
81
                        })
82
                        ->thenInvalid('Locale cookie key should be a string')
83
                    ->end()
84
                ->end()
85
                ->arrayNode('attribute_support')
86
                    ->isRequired()
87
                    ->children()
88
                        ->scalarNode('email_to')
89
                            ->info('Email address to which attributes are sent')
90
                            ->isRequired()
91
                            ->validate()
92
                                ->ifTrue(function ($email) {
93
                                    return !is_string($email);
94
                                })
95
                                ->thenInvalid('Email address to which attributes are sent should be a string')
96
                            ->end()
97
                        ->end()
98
                        ->scalarNode('email_from')
99
                            ->info('mail address from which attributes are sent')
100
                            ->isRequired()
101
                            ->validate()
102
                                ->ifTrue(function ($email) {
103
                                    return !is_string($email);
104
                                })
105
                                ->thenInvalid('Email address from which attributes are sent should be a string')
106
                            ->end()
107
                        ->end()
108
                    ->end()
109
                ->end()
110
            ->end();
111
112
        return $treeBuilder;
113
    }
114
}
115