Completed
Pull Request — develop (#92)
by Boy
02:59
created

Configuration::getConfigTreeBuilder()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 55
Code Lines 47

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 55
rs 9.7692
cc 3
eloc 47
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 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\StepupGateway\GatewayBundle\DependencyInjection;
20
21
use Surfnet\StepupBundle\Exception\DomainException;
22
use Surfnet\StepupBundle\Exception\InvalidArgumentException;
23
use Surfnet\StepupBundle\Value\SecondFactorType;
24
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
25
use Symfony\Component\Config\Definition\ConfigurationInterface;
26
27
final class Configuration implements ConfigurationInterface
28
{
29
    public function getConfigTreeBuilder()
30
    {
31
        $treeBuilder = new TreeBuilder();
32
33
        $rootNode = $treeBuilder->root('surfnet_stepup_gateway_gateway');
34
35
        $rootNode
36
            ->children()
37
                ->scalarNode('intrinsic_loa')
38
                    ->isRequired()
39
                ->end()
40
                ->arrayNode('enabled_second_factors')
41
                    ->isRequired()
42
                    ->prototype('scalar')
43
                        ->validate()
44
                            ->ifTrue(function ($type) {
45
                                try {
46
                                    new SecondFactorType($type);
47
                                } catch (InvalidArgumentException $e) {
48
                                    return true;
49
                                } catch (DomainException $e) {
50
                                    return true;
51
                                }
52
                            })
53
                            ->thenInvalid(
54
                                'Enabled second factor type "%s" is not one of the valid types. See SecondFactorType'
55
                            )
56
                        ->end()
57
                    ->end()
58
                ->end()
59
                ->arrayNode('loa_domains')
60
                    ->isRequired()
61
                    ->children()
62
                        ->arrayNode('gateway')
63
                            ->prototype('array')
64
                                ->children()
65
                                    ->scalarNode('loa')->isRequired()->end()
66
                                    ->scalarNode('ref')->isRequired()->end()
67
                                ->end()
68
                            ->end()
69
                        ->end()
70
                        ->arrayNode('second_factor_only')
71
                            ->prototype('array')
72
                                ->children()
73
                                    ->scalarNode('loa')->isRequired()->end()
74
                                    ->scalarNode('ref')->isRequired()->end()
75
                                ->end()
76
                            ->end()
77
                        ->end()
78
                    ->end()
79
                ->end()
80
            ->end();
81
82
        return $treeBuilder;
83
    }
84
}
85