Passed
Push — main ( 964870...8374cd )
by Daniel
08:40 queued 03:10
created

Configuration::addUserNode()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 90
Code Lines 88

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 88
nc 1
nop 1
dl 0
loc 90
ccs 0
cts 88
cp 0
crap 2
rs 8.2617
c 0
b 0
f 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 Silverback API Components Bundle Project
5
 *
6
 * (c) Daniel West <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Silverback\ApiComponentsBundle\DependencyInjection;
15
16
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
17
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
18
use Symfony\Component\Config\Definition\ConfigurationInterface;
19
20
/**
21
 * @author Daniel West <[email protected]>
22
 */
23
class Configuration implements ConfigurationInterface
24
{
25
    public function getConfigTreeBuilder(): TreeBuilder
26
    {
27
        $treeBuilder = new TreeBuilder('silverback_api_components');
28
        $rootNode = $treeBuilder->getRootNode();
29
        $rootNode
30
            ->children()
31
                ->scalarNode('website_name')->isRequired()->end()
32
                ->scalarNode('table_prefix')->defaultValue('_acb_')->end()
33
                ->scalarNode('metadata_key')->defaultValue('_metadata')->end()
34
            ->end();
35
36
        $this->addRouteSecurityNode($rootNode);
37
        $this->addRoutableSecurityNode($rootNode);
38
        $this->addRefreshTokenNode($rootNode);
39
        $this->addPublishableNode($rootNode);
40
        $this->addEnabledComponentsNode($rootNode);
41
        $this->addUserNode($rootNode);
42
43
        return $treeBuilder;
44
    }
45
46
    private function addRouteSecurityNode(ArrayNodeDefinition $rootNode): void
47
    {
48
        $rootNode
49
            ->children()
50
                ->arrayNode('route_security')
51
                    ->arrayPrototype()
52
                        ->children()
53
                            ->scalarNode('route')->end()
54
                            ->scalarNode('security')->end()
0 ignored issues
show
Bug introduced by
The method scalarNode() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of Symfony\Component\Config...der\NodeParentInterface such as Symfony\Component\Config...ion\Builder\NodeBuilder. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

54
                            ->/** @scrutinizer ignore-call */ scalarNode('security')->end()
Loading history...
55
                        ->end()
56
                    ->end()
57
                ->end()
58
            ->end();
59
    }
60
61
    private function addRoutableSecurityNode(ArrayNodeDefinition $rootNode): void
62
    {
63
        $rootNode
64
            ->children()
65
                ->scalarNode('routable_security')->defaultNull()->end()
66
            ->end();
0 ignored issues
show
Bug introduced by
The method end() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Symfony\Component\Config...ion\Builder\TreeBuilder. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

66
            ->/** @scrutinizer ignore-call */ end();
Loading history...
67
    }
68
69
    private function addRefreshTokenNode(ArrayNodeDefinition $rootNode): void
70
    {
71
        $rootNode
72
            ->children()
73
                ->arrayNode('refresh_token')
74
                    ->addDefaultsIfNotSet()
75
                    ->children()
76
                        ->scalarNode('handler_id')->cannotBeEmpty()->isRequired()->end()
77
                        ->arrayNode('options')
0 ignored issues
show
Bug introduced by
The method arrayNode() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of Symfony\Component\Config...der\NodeParentInterface such as Symfony\Component\Config...ion\Builder\NodeBuilder. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

77
                        ->/** @scrutinizer ignore-call */ arrayNode('options')
Loading history...
78
                            ->useAttributeAsKey('key')
79
                            ->prototype('variable')->end()
80
                        ->end()
81
                        ->scalarNode('cookie_name')->cannotBeEmpty()->isRequired()->end()
82
                        ->scalarNode('ttl')->cannotBeEmpty()->isRequired()->end()
83
                        ->scalarNode('database_user_provider')->cannotBeEmpty()->isRequired()->end()
84
                    ->end()
85
                ->end()
86
            ->end();
87
    }
88
89
    private function addPublishableNode(ArrayNodeDefinition $rootNode): void
90
    {
91
        $rootNode
92
            ->children()
93
                ->arrayNode('publishable')
94
                    ->addDefaultsIfNotSet()
95
                    ->children()
96
                        ->scalarNode('permission')->cannotBeEmpty()->isRequired()->end()
97
                    ->end()
98
                ->end()
99
            ->end();
100
    }
101
102
    private function addEnabledComponentsNode(ArrayNodeDefinition $rootNode): void
103
    {
104
        $rootNode
105
            ->children()
106
                ->arrayNode('enabled_components')
107
                    ->addDefaultsIfNotSet()
108
                    ->children()
109
                        ->booleanNode('form')->defaultValue(true)->end()
110
                        ->booleanNode('collection')->defaultValue(true)->end()
0 ignored issues
show
Bug introduced by
The method booleanNode() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of Symfony\Component\Config...der\NodeParentInterface such as Symfony\Component\Config...ion\Builder\NodeBuilder. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

110
                        ->/** @scrutinizer ignore-call */ booleanNode('collection')->defaultValue(true)->end()
Loading history...
111
                    ->end()
112
                ->end()
113
            ->end();
114
    }
115
116
    private function addUserNode(ArrayNodeDefinition $rootNode): void
117
    {
118
        $rootNode
119
            ->children()
120
                ->arrayNode('user')
121
                    ->addDefaultsIfNotSet()
122
                    ->children()
123
                        ->scalarNode('class_name')
124
                            ->isRequired()
125
                        ->end()
126
                        ->arrayNode('email_verification')
127
                            ->canBeDisabled()
128
                            ->addDefaultsIfNotSet()
129
                            ->children()
130
                                ->arrayNode('email')
131
                                    ->children()
132
                                        ->scalarNode('redirect_path_query')->end()
133
                                        ->scalarNode('default_redirect_path')->isRequired()->end()
134
                                        ->scalarNode('subject')->cannotBeEmpty()->defaultValue('Please verify your email')->end()
135
                                    ->end()
136
                                ->end()
137
                                ->booleanNode('default_value')->isRequired()->end()
138
                                ->booleanNode('verify_on_change')->isRequired()->end()
139
                                ->booleanNode('verify_on_register')->isRequired()->end()
140
                                ->booleanNode('deny_unverified_login')->isRequired()->end()
141
                            ->end()
142
                        ->end()
143
                        ->arrayNode('new_email_confirmation')
144
                            ->addDefaultsIfNotSet()
145
                            ->children()
146
                                ->arrayNode('email')
147
                                    ->children()
148
                                        ->scalarNode('redirect_path_query')->end()
149
                                        ->scalarNode('default_redirect_path')->isRequired()->end()
150
                                        ->scalarNode('subject')->cannotBeEmpty()->defaultValue('Please confirm your new email address')->end()
151
                                    ->end()
152
                                ->end()
153
                                ->integerNode('request_timeout_seconds')->defaultValue(86400)->end()
154
                            ->end()
155
                        ->end()
156
                        ->arrayNode('password_reset')
157
                            ->addDefaultsIfNotSet()
158
                            ->children()
159
                                ->arrayNode('email')
160
                                    ->children()
161
                                        ->scalarNode('redirect_path_query')->end()
162
                                        ->scalarNode('default_redirect_path')->isRequired()->end()
163
                                        ->scalarNode('subject')->cannotBeEmpty()->defaultValue('Your password has been reset')->end()
164
                                    ->end()
165
                                ->end()
166
                                ->integerNode('repeat_ttl_seconds')->defaultValue(8600)->end()
167
                                ->integerNode('request_timeout_seconds')->defaultValue(3600)->end()
168
                            ->end()
169
                        ->end()
170
                        ->arrayNode('emails')
171
                            ->addDefaultsIfNotSet()
172
                            ->children()
173
                                ->arrayNode('welcome')
174
                                    ->canBeDisabled()
175
                                    ->addDefaultsIfNotSet()
176
                                    ->children()
177
                                        ->scalarNode('subject')->cannotBeEmpty()->defaultValue('Welcome to {{ website_name }}')->end()
178
                                    ->end()
179
                                ->end()
180
                                ->arrayNode('user_enabled')
181
                                    ->canBeDisabled()
182
                                    ->addDefaultsIfNotSet()
183
                                    ->children()
184
                                        ->scalarNode('subject')->cannotBeEmpty()->defaultValue('Your account has been enabled')->end()
185
                                    ->end()
186
                                ->end()
187
                                ->arrayNode('username_changed')
188
                                    ->canBeDisabled()
189
                                    ->addDefaultsIfNotSet()
190
                                    ->children()
191
                                        ->scalarNode('subject')->cannotBeEmpty()->defaultValue('Your username has been updated')->end()
192
                                    ->end()
193
                                ->end()
194
                                ->arrayNode('password_changed')
195
                                    ->canBeDisabled()
196
                                    ->addDefaultsIfNotSet()
197
                                    ->children()
198
                                        ->scalarNode('subject')->cannotBeEmpty()->defaultValue('Your password has been changed')->end()
199
                                    ->end()
200
                                ->end()
201
                            ->end()
202
                        ->end()
203
                    ->end()
204
                ->end()
205
            ->end();
206
    }
207
}
208