Passed
Pull Request — feature/publishable (#31)
by Vincent
07:19
created

Configuration::addEnabledComponentsNode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

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

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

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

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