Passed
Pull Request — feature/unit-tests (#37)
by Daniel
05:46
created

Configuration   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 123
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 106
dl 0
loc 123
ccs 107
cts 107
cp 1
rs 10
c 2
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addEnabledComponentsNode() 0 12 1
A getConfigTreeBuilder() 0 15 1
A addSecurityNode() 0 13 1
B addUserNode() 0 75 1
1
<?php
2
3
/*
4
 * This file is part of the Silverback API Component 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\ApiComponentBundle\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_component');
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
            ->end();
34
35 1
        $this->addSecurityNode($rootNode);
36 1
        $this->addEnabledComponentsNode($rootNode);
37 1
        $this->addUserNode($rootNode);
38
39 1
        return $treeBuilder;
40
    }
41
42 1
    private function addSecurityNode(ArrayNodeDefinition $rootNode): void
43
    {
44
        $rootNode
45 1
            ->children()
46 1
                ->arrayNode('security')
47 1
                    ->addDefaultsIfNotSet()
48 1
                    ->children()
49 1
                        ->arrayNode('tokens')
50 1
                            ->prototype('scalar')->end()
51 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

51
                        ->/** @scrutinizer ignore-call */ end()
Loading history...
52 1
                    ->end()
53 1
                ->end()
54 1
            ->end();
55 1
    }
56
57 1
    private function addEnabledComponentsNode(ArrayNodeDefinition $rootNode): void
58
    {
59
        $rootNode
60 1
            ->children()
61 1
                ->arrayNode('enabled_components')
62 1
                    ->addDefaultsIfNotSet()
63 1
                    ->children()
64 1
                        ->booleanNode('form')->defaultValue(true)->end()
65 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

65
                        ->/** @scrutinizer ignore-call */ booleanNode('collection')->defaultValue(true)->end()
Loading history...
66 1
                    ->end()
67 1
                ->end()
68 1
            ->end();
69 1
    }
70
71 1
    private function addUserNode(ArrayNodeDefinition $rootNode): void
72
    {
73
        $rootNode
74 1
            ->children()
75 1
                ->arrayNode('user')
76 1
                    ->addDefaultsIfNotSet()
77 1
                    ->children()
78 1
                        ->scalarNode('class_name')->isRequired()->end()
79 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

79
                        ->/** @scrutinizer ignore-call */ arrayNode('email_verification')
Loading history...
80 1
                            ->canBeDisabled()
81 1
                            ->addDefaultsIfNotSet()
82 1
                            ->children()
83 1
                                ->arrayNode('email')
84 1
                                    ->children()
85 1
                                        ->scalarNode('redirect_path_query')->end()
86 1
                                        ->scalarNode('default_redirect_path')->isRequired()->end()
87 1
                                        ->scalarNode('subject')->defaultValue('')->end()
88 1
                                    ->end()
89 1
                                ->end()
90 1
                                ->booleanNode('default_value')->isRequired()->end()
91 1
                                ->booleanNode('verify_on_change')->isRequired()->end()
92 1
                                ->booleanNode('verify_on_register')->isRequired()->end()
93 1
                                ->booleanNode('deny_unverified_login')->isRequired()->end()
94 1
                            ->end()
95 1
                        ->end()
96 1
                        ->arrayNode('password_reset')
97 1
                            ->addDefaultsIfNotSet()
98 1
                            ->children()
99 1
                                ->arrayNode('email')
100 1
                                    ->children()
101 1
                                        ->scalarNode('redirect_path_query')->end()
102 1
                                        ->scalarNode('default_redirect_path')->isRequired()->end()
103 1
                                        ->scalarNode('subject')->defaultValue('')->end()
104 1
                                    ->end()
105 1
                                ->end()
106 1
                                ->integerNode('repeat_ttl_seconds')->defaultValue(8600)->end()
107 1
                                ->integerNode('request_timeout_seconds')->defaultValue(3600)->end()
108 1
                            ->end()
109 1
                        ->end()
110 1
                        ->arrayNode('emails')
111 1
                            ->addDefaultsIfNotSet()
112 1
                            ->children()
113 1
                                ->arrayNode('welcome')
114 1
                                    ->canBeDisabled()
115 1
                                    ->addDefaultsIfNotSet()
116 1
                                    ->children()
117 1
                                        ->scalarNode('subject')->defaultValue('Welcome to {{ website_name }}')->end()
118 1
                                    ->end()
119 1
                                ->end()
120 1
                                ->arrayNode('user_enabled')
121 1
                                    ->canBeDisabled()
122 1
                                    ->addDefaultsIfNotSet()
123 1
                                    ->children()
124 1
                                        ->scalarNode('subject')->defaultValue('Your account has been enabled')->end()
125 1
                                    ->end()
126 1
                                ->end()
127 1
                                ->arrayNode('username_changed')
128 1
                                    ->canBeDisabled()
129 1
                                    ->addDefaultsIfNotSet()
130 1
                                    ->children()
131 1
                                        ->scalarNode('subject')->defaultValue('Your username has been updated')->end()
132 1
                                    ->end()
133 1
                                ->end()
134 1
                                ->arrayNode('password_changed')
135 1
                                    ->canBeDisabled()
136 1
                                    ->addDefaultsIfNotSet()
137 1
                                    ->children()
138 1
                                        ->scalarNode('subject')->defaultValue('Your password has been changed')->end()
139 1
                                    ->end()
140 1
                                ->end()
141 1
                            ->end()
142 1
                        ->end()
143 1
                    ->end()
144 1
                ->end()
145 1
            ->end();
146 1
    }
147
}
148