Completed
Push — feature/gssp-add-through-confi... ( bd6c70 )
by
unknown
02:42
created

Configuration::addProvidersSection()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 90
Code Lines 85

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 85
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
 * Copyright 2014 SURFnet bv
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 Surfnet\StepupSelfService\SamlStepupProviderBundle\DependencyInjection;
20
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
class Configuration implements ConfigurationInterface
26
{
27
    public function getConfigTreeBuilder()
28
    {
29
        $treeBuilder = new TreeBuilder();
30
        $rootNode = $treeBuilder->root('surfnet_stepup_self_service_saml_stepup_provider');
31
32
        $this->addRoutesSection($rootNode);
33
        $this->addProvidersSection($rootNode);
34
35
        return $treeBuilder;
36
    }
37
38
    /**
39
     * @param ArrayNodeDefinition $rootNode
40
     */
41
    private function addRoutesSection(ArrayNodeDefinition $rootNode)
42
    {
43
        $rootNode
44
            ->children()
45
            ->arrayNode('routes')
46
                ->children()
47
                    ->scalarNode('consume_assertion')
48
                        ->isRequired()
49
                        ->validate()
50
                            ->ifTrue(function ($v) {
51
                                return !is_string($v) || strlen($v) === 0;
52
                            })
53
                            ->thenInvalid('Consume assertion route must be a non-empty string')
54
                        ->end()
55
                    ->end()
56
                    ->scalarNode('metadata')
57
                        ->isRequired()
58
                        ->validate()
59
                            ->ifTrue(function ($v) {
60
                                return !is_string($v) || strlen($v) === 0;
61
                            })
62
                            ->thenInvalid('Metadata route must be a non-empty string')
63
                        ->end()
64
                    ->end()
65
                ->end()
66
            ->end();
67
    }
68
69
    /**
70
     * @param ArrayNodeDefinition $rootNode
71
     */
72
    private function addProvidersSection(ArrayNodeDefinition $rootNode)
73
    {
74
        /** @var ArrayNodeDefinition $protoType */
75
        $protoType = $rootNode
76
            ->children()
77
                ->arrayNode('providers')
78
                ->isRequired()
79
                ->requiresAtLeastOneElement()
80
                ->useAttributeAsKey('type')
81
                ->prototype('array');
82
83
        $protoType
84
            ->children()
85
                ->arrayNode('hosted')
86
                    ->children()
87
                        ->arrayNode('service_provider')
88
                            ->children()
89
                                ->scalarNode('public_key')
90
                                    ->isRequired()
91
                                    ->info('The absolute path to the public key used to sign AuthnRequests')
92
                                ->end()
93
                                ->scalarNode('private_key')
94
                                    ->isRequired()
95
                                    ->info('The absolute path to the private key used to sign AuthnRequests')
96
                                ->end()
97
                            ->end()
98
                        ->end()
99
                        ->arrayNode('metadata')
100
                            ->children()
101
                                ->scalarNode('public_key')
102
                                    ->isRequired()
103
                                    ->info('The absolute path to the public key used to sign the metadata')
104
                                ->end()
105
                                ->scalarNode('private_key')
106
                                    ->isRequired()
107
                                    ->info('The absolute path to the private key used to sign the metadata')
108
                                ->end()
109
                            ->end()
110
                        ->end()
111
                    ->end()
112
                ->end()
113
                ->arrayNode('remote')
114
                    ->children()
115
                        ->scalarNode('entity_id')
116
                            ->isRequired()
117
                            ->info('The EntityID of the remote identity provider')
118
                        ->end()
119
                        ->scalarNode('sso_url')
120
                            ->isRequired()
121
                            ->info('The name of the route to generate the SSO URL')
122
                        ->end()
123
                        ->scalarNode('certificate')
124
                            ->isRequired()
125
                            ->info(
126
                                'The contents of the certificate used to sign the AuthnResponse with, if different from'
127
                                . ' the public key configured below'
128
                            )
129
                        ->end()
130
                    ->end()
131
                ->end()
132
                ->arrayNode('view_config')
133
                    ->children()
134
                        ->scalarNode('loa')
135
                            ->isRequired()
136
                            ->info('The loa level (for now 1-3 are supported)')
137
                        ->end()
138
                        ->scalarNode('logo')
139
                            ->isRequired()
140
                            ->info('The absolute path to the logo of the gssp')
141
                        ->end()
142
                        ->scalarNode('alt')
143
                            ->isRequired()
144
                            ->info('The alt text of the gssp logo')
145
                        ->end()
146
                        ->scalarNode('title')
147
                            ->isRequired()
148
                            ->info('The title of the gssp')
149
                        ->end()
150
                        ->scalarNode('description')
151
                            ->isRequired()
152
                            ->info('The description of the gssp')
153
                        ->end()
154
                        ->scalarNode('button_use')
155
                            ->isRequired()
156
                            ->info('The text shown on the use button')
157
                        ->end()
158
                    ->end()
159
                ->end()
160
            ->end();
161
    }
162
}
163