Passed
Push — feature/uploadable ( 7c6d25...a7ed20 )
by Daniel
11:07
created

Configuration::addSecurityNode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 1
dl 0
loc 13
ccs 11
cts 11
cp 1
crap 1
rs 9.9
c 0
b 0
f 0
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 1
    public function getConfigTreeBuilder(): TreeBuilder
26
    {
27 1
        $treeBuilder = new TreeBuilder('silverback_api_components');
28 1
        $rootNode = $treeBuilder->getRootNode();
29
        $rootNode
30 1
            ->children()
31 1
                ->scalarNode('website_name')->isRequired()->end()
32 1
                ->scalarNode('table_prefix')->defaultValue('_acb_')->end()
33 1
                ->scalarNode('metadata_key')->defaultValue('_metadata')->end()
34 1
            ->end();
35
36 1
        $this->addPublishableNode($rootNode);
37 1
        $this->addSecurityNode($rootNode);
38 1
        $this->addEnabledComponentsNode($rootNode);
39 1
        $this->addUserNode($rootNode);
40
41 1
        return $treeBuilder;
42
    }
43
44 1
    private function addPublishableNode(ArrayNodeDefinition $rootNode): void
45
    {
46
        $rootNode
47 1
            ->children()
48 1
                ->arrayNode('publishable')
49 1
                    ->addDefaultsIfNotSet()
50 1
                    ->children()
51 1
                        ->scalarNode('permission')
52 1
                            ->cannotBeEmpty()
53 1
                            ->isRequired()
54 1
                        ->end()
55 1
                    ->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

55
                    ->/** @scrutinizer ignore-call */ end()
Loading history...
56 1
                ->end()
57 1
            ->end();
58 1
    }
59
60 1
    private function addSecurityNode(ArrayNodeDefinition $rootNode): void
61
    {
62
        $rootNode
63 1
            ->children()
64 1
                ->arrayNode('security')
65 1
                    ->addDefaultsIfNotSet()
66 1
                    ->children()
67 1
                        ->arrayNode('tokens')
68 1
                            ->prototype('scalar')->end()
69 1
                        ->end()
70 1
                    ->end()
71 1
                ->end()
72 1
            ->end();
73 1
    }
74
75 1
    private function addEnabledComponentsNode(ArrayNodeDefinition $rootNode): void
76
    {
77
        $rootNode
78 1
            ->children()
79 1
                ->arrayNode('enabled_components')
80 1
                    ->addDefaultsIfNotSet()
81 1
                    ->children()
82 1
                        ->booleanNode('form')->defaultValue(true)->end()
83 1
                        ->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

83
                        ->/** @scrutinizer ignore-call */ booleanNode('collection')->defaultValue(true)->end()
Loading history...
84 1
                    ->end()
85 1
                ->end()
86 1
            ->end();
87 1
    }
88
89 1
    private function addUserNode(ArrayNodeDefinition $rootNode): void
90
    {
91
        $rootNode
92 1
            ->children()
93 1
                ->arrayNode('user')
94 1
                    ->addDefaultsIfNotSet()
95 1
                    ->children()
96 1
                        ->scalarNode('class_name')->isRequired()->end()
97 1
                        ->arrayNode('email_verification')
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

97
                        ->/** @scrutinizer ignore-call */ arrayNode('email_verification')
Loading history...
98 1
                            ->canBeDisabled()
99 1
                            ->addDefaultsIfNotSet()
100 1
                            ->children()
101 1
                                ->arrayNode('email')
102 1
                                    ->children()
103 1
                                        ->scalarNode('redirect_path_query')->end()
104 1
                                        ->scalarNode('default_redirect_path')->isRequired()->end()
105 1
                                        ->scalarNode('subject')->cannotBeEmpty()->defaultValue('Please verify your email')->end()
106 1
                                    ->end()
107 1
                                ->end()
108 1
                                ->booleanNode('default_value')->isRequired()->end()
109 1
                                ->booleanNode('verify_on_change')->isRequired()->end()
110 1
                                ->booleanNode('verify_on_register')->isRequired()->end()
111 1
                                ->booleanNode('deny_unverified_login')->isRequired()->end()
112 1
                            ->end()
113 1
                        ->end()
114 1
                        ->arrayNode('password_reset')
115 1
                            ->addDefaultsIfNotSet()
116 1
                            ->children()
117 1
                                ->arrayNode('email')
118 1
                                    ->children()
119 1
                                        ->scalarNode('redirect_path_query')->end()
120 1
                                        ->scalarNode('default_redirect_path')->isRequired()->end()
121 1
                                        ->scalarNode('subject')->cannotBeEmpty()->defaultValue('Your password has been reset')->end()
122 1
                                    ->end()
123 1
                                ->end()
124 1
                                ->integerNode('repeat_ttl_seconds')->defaultValue(8600)->end()
125 1
                                ->integerNode('request_timeout_seconds')->defaultValue(3600)->end()
126 1
                            ->end()
127 1
                        ->end()
128 1
                        ->arrayNode('emails')
129 1
                            ->addDefaultsIfNotSet()
130 1
                            ->children()
131 1
                                ->arrayNode('welcome')
132 1
                                    ->canBeDisabled()
133 1
                                    ->addDefaultsIfNotSet()
134 1
                                    ->children()
135 1
                                        ->scalarNode('subject')->cannotBeEmpty()->defaultValue('Welcome to {{ website_name }}')->end()
136 1
                                    ->end()
137 1
                                ->end()
138 1
                                ->arrayNode('user_enabled')
139 1
                                    ->canBeDisabled()
140 1
                                    ->addDefaultsIfNotSet()
141 1
                                    ->children()
142 1
                                        ->scalarNode('subject')->cannotBeEmpty()->defaultValue('Your account has been enabled')->end()
143 1
                                    ->end()
144 1
                                ->end()
145 1
                                ->arrayNode('username_changed')
146 1
                                    ->canBeDisabled()
147 1
                                    ->addDefaultsIfNotSet()
148 1
                                    ->children()
149 1
                                        ->scalarNode('subject')->cannotBeEmpty()->defaultValue('Your username has been updated')->end()
150 1
                                    ->end()
151 1
                                ->end()
152 1
                                ->arrayNode('password_changed')
153 1
                                    ->canBeDisabled()
154 1
                                    ->addDefaultsIfNotSet()
155 1
                                    ->children()
156 1
                                        ->scalarNode('subject')->cannotBeEmpty()->defaultValue('Your password has been changed')->end()
157 1
                                    ->end()
158 1
                                ->end()
159 1
                            ->end()
160 1
                        ->end()
161 1
                    ->end()
162 1
                ->end()
163 1
            ->end();
164 1
    }
165
}
166