GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Configuration::addCaptchaSection()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 55

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 41
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 55
rs 8.9818
c 0
b 0
f 0
ccs 41
cts 41
cp 1
cc 1
nc 1
nop 1
crap 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
namespace Netgen\Bundle\InformationCollectionBundle\DependencyInjection;
4
5
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\Configuration as SiteAccessConfiguration;
6
use Netgen\InformationCollection\Core\Action\EmailAction;
7
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
8
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
9
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
10
use Netgen\InformationCollection\API\ConfigurationConstants;
11
12
/**
13
 * This is the class that validates and merges configuration from your app/config files.
14
 *
15
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
16 4
 */
17
class Configuration extends SiteAccessConfiguration
18 4
{
19 4
    /**
20
     * {@inheritdoc}
21 4
     */
22 4
    public function getConfigTreeBuilder()
23 4
    {
24 4
        $treeBuilder = new TreeBuilder(ConfigurationConstants::SETTINGS_ROOT);
25 4
26 4
        // Keep compatibility with symfony/config < 4.2
27 4
        if (!method_exists($treeBuilder, 'getRootNode')) {
28 4
            $rootNode = $treeBuilder->root(ConfigurationConstants::SETTINGS_ROOT);
0 ignored issues
show
Bug introduced by
The method root() does not seem to exist on object<Symfony\Component...on\Builder\TreeBuilder>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
29 4
        } else {
30 4
            $rootNode = $treeBuilder->getRootNode();
31 4
        }
32 4
33
        if ($rootNode instanceof ArrayNodeDefinition) {
34 4
            $nodeBuilder = $this->generateScopeBaseNode($rootNode);
35 4
            $this->addCaptchaSection($nodeBuilder);
36 4
            $this->addActionsSection($nodeBuilder);
37 4
            $this->addActionConfigSection($nodeBuilder);
38 4
39 4
            $nodeBuilder->end();
40 4
        }
41 4
42
        return $treeBuilder;
43 4
    }
44 4
45
    private function addCaptchaSection(NodeBuilder $nodeBuilder)
46 4
    {
47 4
        $nodeBuilder
48 4
            ->arrayNode('captcha')
49 4
                ->addDefaultsIfNotSet()
50 4
                ->children()
51 4
                    ->booleanNode('enabled')
52 4
                    ->defaultFalse()
53 4
                ->end()
54 4
                ->arrayNode('override_by_type')
55 4
                    ->prototype('array')
56 4
                        ->children()
57 4
                            ->booleanNode('enabled')->defaultFalse()->end()
58 4
                            ->scalarNode('secret')->cannotBeEmpty()->end()
59 4
                            ->scalarNode('site_key')->cannotBeEmpty()->end()
60 4
                            ->arrayNode('options')
61 4
                                ->children()
62 4
                                    ->scalarNode('hostname')->cannotBeEmpty()->end()
63 4
                                    ->scalarNode('apk_package_name')->cannotBeEmpty()->end()
64 4
                                    ->scalarNode('action')->cannotBeEmpty()->end()
65 4
                                    ->scalarNode('score_threshold')->cannotBeEmpty()->end()
66 4
                                    ->scalarNode('challenge_timeout')->cannotBeEmpty()->end()
67 4
                                ->end()
68 4
                            ->end()
69 4
                        ->end()
70 4
                    ->end()
71 4
                ->end()
72 4
                ->scalarNode('secret')
73 4
                    ->isRequired()
74 4
                ->end()
75 4
                ->scalarNode('site_key')
76 4
                    ->isRequired()
77 4
                ->end()
78 4
                ->arrayNode('options')
79 4
                    ->children()
80 4
                        ->scalarNode('hostname')
81 4
                            ->cannotBeEmpty()
82 4
                        ->end()
83 4
                        ->scalarNode('apk_package_name')
84 4
                            ->cannotBeEmpty()
85 4
                        ->end()
86
                        ->scalarNode('action')
87 4
                            ->cannotBeEmpty()
88
                        ->end()
89
                        ->scalarNode('score_threshold')
90
                            ->cannotBeEmpty()
91
                        ->end()
92
                        ->scalarNode('challenge_timeout')
93
                            ->cannotBeEmpty()
94
                        ->end()
95
                    ->end()
96
                ->end()
97
            ->end()
98
            ->end();
99
    }
100
101
    private function addActionsSection(NodeBuilder $nodeBuilder)
102
    {
103
        $nodeBuilder
104
            ->arrayNode(ConfigurationConstants::ACTIONS)
105
                ->isRequired()
106
                ->normalizeKeys(false)
107
                    ->children()
108
                        ->arrayNode(ConfigurationConstants::SETTINGS_DEFAULT)
109
                            ->isRequired()
110
                            ->prototype('scalar')
111
                                ->isRequired()
112
                                ->cannotBeEmpty()
113
                            ->end()
114
                        ->end()
115
                        ->arrayNode(ConfigurationConstants::CONTENT_TYPES)
116
                            ->prototype('array')
117
                            ->prototype('scalar')
118
                                ->isRequired()
119
                                ->cannotBeEmpty()
120
                        ->end()
121
                    ->end()
122
                ->end()
123
            ->end()
124
        ->end();
125
    }
126
127
    private function addActionConfigSection(NodeBuilder $nodeBuilder)
128
    {
129
        $nodeBuilder
130
            ->arrayNode(ConfigurationConstants::ACTION_CONFIG)
131
                ->isRequired()
132
                ->normalizeKeys(false)
133
                    ->children()
134
                        ->arrayNode(ConfigurationConstants::ACTION_AUTO_RESPONDER)
135
                            ->addDefaultsIfNotSet()
136
                                ->children()
137
                                    ->arrayNode(ConfigurationConstants::TEMPLATES)
138
                                        ->children()
139
                                            ->scalarNode(ConfigurationConstants::SETTINGS_DEFAULT)
140
                                                ->isRequired()
141
                                                ->cannotBeEmpty()
142
                                            ->end()
143
                                            ->arrayNode(ConfigurationConstants::CONTENT_TYPES)
144
                                                ->prototype('scalar')
145
                                                    ->isRequired()
146
                                                    ->cannotBeEmpty()
147
                                                ->end()
148
                                            ->end()
149
                                        ->end()
150
                                    ->end()
151
                                    ->arrayNode(ConfigurationConstants::DEFAULT_VARIABLES)
152
                                        ->children()
153
                                            ->scalarNode(ConfigurationConstants::EMAIL_SENDER)
154
                                                ->isRequired()
155
                                                ->cannotBeEmpty()
156
                                            ->end()
157
                                            ->scalarNode(ConfigurationConstants::EMAIL_SUBJECT)
158
                                                ->isRequired()
159
                                                ->cannotBeEmpty()
160
                                            ->end()
161
                                            ->scalarNode(ConfigurationConstants::EMAIL_FIELD_IDENTIFIER)
162
                                                ->defaultValue(ConfigurationConstants::ACTION_EMAIL)
163
                                                ->cannotBeEmpty()
164
                                            ->end()
165
                                        ->end()
166
                                    ->end()
167
                                ->end()
168
                            ->end()
169
                        ->arrayNode('email')
170
                            ->children()
171
                                ->arrayNode(ConfigurationConstants::TEMPLATES)
172
                                    ->children()
173
                                        ->scalarNode(ConfigurationConstants::SETTINGS_DEFAULT)
174
                                            ->isRequired()
175
                                            ->cannotBeEmpty()
176
                                        ->end()
177
                                        ->arrayNode(ConfigurationConstants::CONTENT_TYPES)
178
                                            ->prototype('scalar')
179
                                                ->isRequired()
180
                                                ->cannotBeEmpty()
181
                                            ->end()
182
                                        ->end()
183
                                    ->end()
184
                                ->end()
185
                                ->arrayNode(ConfigurationConstants::ATTACHMENTS)
186
                                    ->children()
187
                                        ->scalarNode(ConfigurationConstants::SETTINGS_DEFAULT)
188
                                            ->isRequired()
189
                                            ->defaultValue(true)
190
                                        ->end()
191
                                        ->arrayNode(ConfigurationConstants::CONTENT_TYPES)
192
                                            ->prototype('scalar')
193
                                                ->isRequired()
194
                                                ->cannotBeEmpty()
195
                                            ->end()
196
                                        ->end()
197
                                    ->end()
198
                                ->end()
199
                                ->arrayNode(ConfigurationConstants::DEFAULT_VARIABLES)
200
                                    ->children()
201
                                        ->scalarNode(ConfigurationConstants::EMAIL_SENDER)
202
                                            ->isRequired()
203
                                            ->cannotBeEmpty()
204
                                        ->end()
205
                                        ->scalarNode(ConfigurationConstants::EMAIL_RECIPIENT)
206
                                            ->isRequired()
207
                                            ->cannotBeEmpty()
208
                                        ->end()
209
                                        ->scalarNode(ConfigurationConstants::EMAIL_SUBJECT)
210
                                            ->cannotBeEmpty()
211
                                        ->end()
212
                                    ->end()
213
                                ->end()
214
                            ->end()
215
                        ->end()
216
                    ->end()
217
            ->end();
218
    }
219
}
220