Passed
Push — v2 ( c87c94...bb2b66 )
by Daniel
05:12
created

Configuration::addEnabledComponentsNode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 1
dl 0
loc 12
ccs 0
cts 10
cp 0
crap 2
rs 9.9332
c 0
b 0
f 0
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
    public function getConfigTreeBuilder(): TreeBuilder
26
    {
27
        $treeBuilder = new TreeBuilder('silverback_api_component');
28
        $rootNode = $treeBuilder->getRootNode();
29
        $rootNode
30
            ->children()
31
                ->scalarNode('website_name')->isRequired()->end()
32
                ->scalarNode('table_prefix')->defaultValue('_acb_')->end()
33
            ->end();
34
35
        $this->addSecurityNode($rootNode);
36
        $this->addEnabledComponentsNode($rootNode);
37
        $this->addUserNode($rootNode);
38
39
        return $treeBuilder;
40
    }
41
42
    private function addSecurityNode(ArrayNodeDefinition $rootNode): void
43
    {
44
        $rootNode
45
            ->children()
46
                ->arrayNode('security')
47
                    ->addDefaultsIfNotSet()
48
                    ->children()
49
                        ->arrayNode('tokens')
50
                            ->prototype('scalar')->end()
51
                        ->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
                    ->end()
53
                ->end()
54
            ->end();
55
    }
56
57
    private function addEnabledComponentsNode(ArrayNodeDefinition $rootNode): void
58
    {
59
        $rootNode
60
            ->children()
61
                ->arrayNode('enabled_components')
62
                    ->addDefaultsIfNotSet()
63
                    ->children()
64
                        ->booleanNode('form')->defaultValue(true)->end()
65
                        ->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
                    ->end()
67
                ->end()
68
            ->end();
69
    }
70
71
    private function addUserNode(ArrayNodeDefinition $rootNode): void
72
    {
73
        $rootNode
74
            ->children()
75
                ->arrayNode('user')
76
                    ->addDefaultsIfNotSet()
77
                    ->children()
78
                        ->scalarNode('class_name')->isRequired()->end()
79
                        ->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
                            ->addDefaultsIfNotSet()
81
                            ->children()
82
                                ->booleanNode('default')->isRequired()->end()
83
                                ->booleanNode('verify_on_register')->isRequired()->end()
84
                                ->booleanNode('deny_unverified_login')->isRequired()->end()
85
                            ->end()
86
                        ->end()
87
                        ->arrayNode('change_email_address')
88
                            ->addDefaultsIfNotSet()
89
                            ->children()
90
                                ->scalarNode('default_verify_path')->isRequired()->end()
91
                            ->end()
92
                        ->end()
93
                        ->arrayNode('password_reset')
94
                            ->addDefaultsIfNotSet()
95
                            ->children()
96
                                ->scalarNode('default_reset_path')->isRequired()->end()
97
                                ->integerNode('repeat_ttl_seconds')->defaultValue(8600)->end()
98
                                ->integerNode('request_timeout_seconds')->defaultValue(3600)->end()
99
                            ->end()
100
                        ->end()
101
                        ->arrayNode('emails')
102
                            ->addDefaultsIfNotSet()
103
                            ->children()
104
                                ->booleanNode('user_welcome')->defaultValue(true)->end()
105
                                ->booleanNode('user_enabled')->defaultValue(true)->end()
106
                                ->booleanNode('user_username_changed')->defaultValue(true)->end()
107
                                ->booleanNode('user_password_changed')->defaultValue(true)->end()
108
                            ->end()
109
                        ->end()
110
                    ->end()
111
                ->end()
112
            ->end();
113
    }
114
}
115