Completed
Push — develop ( a368ca...435c97 )
by
unknown
07:19 queued 04:10
created

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 69

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 69
rs 8.6763
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
 * Copyright 2018 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\UserLifecycleApiClientBundle\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_user_lifecycle_api_client');
30
31
        $rootNode
32
            ->children()
33
                ->booleanNode('enabled')
34
                    ->isRequired()
35
                    ->info('Give user the option to download their data')
36
                ->end()
37
                ->arrayNode('http_client')
38
                    ->children()
39
                        ->scalarNode('base_url')
40
                            ->info('The base URL of the user lifecycle API host')
41
                            ->isRequired()
42
                            ->cannotBeEmpty()
43
                            ->validate()
44
                                ->ifTrue(function ($baseUrl) {
45
                                    return !is_string($baseUrl);
46
                                })
47
                                ->thenInvalid('The user lifecycle API base URL should be a string')
48
                            ->end()
49
                            ->validate()
50
                                ->ifTrue(function ($baseUrl) {
51
                                    return !filter_var($baseUrl, FILTER_VALIDATE_URL);
52
                                })
53
                                ->thenInvalid('The user lifecycle base URL should be a valid URL')
54
                            ->end()
55
                            ->validate()
56
                                ->ifTrue(function ($baseUrl) {
57
                                    $path = parse_url($baseUrl, PHP_URL_PATH);
58
59
                                    return $path[strlen($path)-1] !== '/';
60
                                })
61
                                ->thenInvalid('The user lifecycle base URL must end in a forward slash')
62
                            ->end()
63
                        ->end()
64
                        ->booleanNode('verify_ssl')
65
                            ->defaultTrue()
66
                        ->end()
67
                        ->scalarNode('username')
68
                            ->info('The username of the API user')
69
                            ->isRequired()
70
                            ->cannotBeEmpty()
71
                            ->validate()
72
                                ->ifTrue(function ($username) {
73
                                    return !is_string($username);
74
                                })
75
                                ->thenInvalid('The user lifecycle username should be a string')
76
                            ->end()
77
                        ->end()
78
                        ->scalarNode('password')
79
                            ->info('The password of the API user')
80
                            ->isRequired()
81
                            ->cannotBeEmpty()
82
                            ->validate()
83
                                ->ifTrue(function ($password) {
84
                                    return !is_string($password);
85
                                })
86
                                ->thenInvalid('The user lifecycle password should be a string')
87
                            ->end()
88
                        ->end()
89
                    ->end()
90
                ->end()
91
            ->end();
92
93
        return $treeBuilder;
94
    }
95
}
96