Passed
Pull Request — feature/publishable (#31)
by Vincent
06:03
created

Configuration::addPublishableNode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 12
c 0
b 0
f 0
dl 0
loc 14
ccs 0
cts 12
cp 0
rs 9.8666
cc 1
nc 1
nop 1
crap 2
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->addPublishableNode($rootNode);
36
        $this->addSecurityNode($rootNode);
37
        $this->addEnabledComponentsNode($rootNode);
38
        $this->addUserNode($rootNode);
39
40
        return $treeBuilder;
41
    }
42
43
    private function addPublishableNode(ArrayNodeDefinition $rootNode): void
44
    {
45
        $rootNode
46
            ->children()
47
                ->arrayNode('publishable')
48
                    ->addDefaultsIfNotSet()
49
                    ->children()
50
                        ->scalarNode('permission')
51
                            ->cannotBeEmpty()
52
                            ->defaultValue(sprintf('is_granted(ROLE_ADMIN)'))
53
                        ->end()
54
                    ->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

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

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

96
                        ->/** @scrutinizer ignore-call */ arrayNode('email_verification')
Loading history...
97
                            ->addDefaultsIfNotSet()
98
                            ->children()
99
                                ->booleanNode('default')->isRequired()->end()
100
                                ->booleanNode('verify_on_register')->isRequired()->end()
101
                                ->booleanNode('deny_unverified_login')->isRequired()->end()
102
                            ->end()
103
                        ->end()
104
                        ->arrayNode('change_email_address')
105
                            ->addDefaultsIfNotSet()
106
                            ->children()
107
                                ->scalarNode('default_verify_path')->isRequired()->end()
108
                            ->end()
109
                        ->end()
110
                        ->arrayNode('password_reset')
111
                            ->addDefaultsIfNotSet()
112
                            ->children()
113
                                ->scalarNode('default_reset_path')->isRequired()->end()
114
                                ->integerNode('repeat_ttl_seconds')->defaultValue(8600)->end()
115
                                ->integerNode('request_timeout_seconds')->defaultValue(3600)->end()
116
                            ->end()
117
                        ->end()
118
                        ->arrayNode('emails')
119
                            ->addDefaultsIfNotSet()
120
                            ->children()
121
                                ->booleanNode('user_welcome')->defaultValue(true)->end()
122
                                ->booleanNode('user_enabled')->defaultValue(true)->end()
123
                                ->booleanNode('user_username_changed')->defaultValue(true)->end()
124
                                ->booleanNode('user_password_changed')->defaultValue(true)->end()
125
                            ->end()
126
                        ->end()
127
                    ->end()
128
                ->end()
129
            ->end();
130
    }
131
}
132