Completed
Pull Request — master (#2737)
by Jeroen
10:25
created

Configuration   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 128
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 98.1%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 2
dl 0
loc 128
ccs 103
cts 105
cp 0.981
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B getConfigTreeBuilder() 0 120 7
1
<?php
2
3
namespace Kunstmaan\AdminBundle\DependencyInjection;
4
5
use Kunstmaan\AdminBundle\Entity\Group;
6
use Kunstmaan\AdminBundle\Entity\User;
7
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
8
use Symfony\Component\Config\Definition\ConfigurationInterface;
9
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
10
11
/**
12
 * This is the class that validates and merges configuration from your app/config files
13
 *
14
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
15
 */
16
class Configuration implements ConfigurationInterface
17
{
18
    /**
19
     * Generates the configuration tree builder.
20
     *
21
     * @return TreeBuilder The tree builder
22
     */
23 16
    public function getConfigTreeBuilder()
24
    {
25 16
        $treeBuilder = new TreeBuilder('kunstmaan_admin');
26 16
        if (method_exists($treeBuilder, 'getRootNode')) {
27 16
            $rootNode = $treeBuilder->getRootNode();
28
        } else {
29
            // BC layer for symfony/config 4.1 and older
30
            $rootNode = $treeBuilder->root('kunstmaan_admin');
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Component\Config...der\TreeBuilder::root() has been deprecated with message: since Symfony 4.3, pass the root name to the constructor instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
31
        }
32
33
        $rootNode
34 16
            ->fixXmlConfig('admin_locale')
35 16
            ->fixXmlConfig('menu_item')
36 16
            ->children()
37 16
                ->scalarNode('website_title')->defaultNull()->end()
38 16
                ->scalarNode('multi_language') //NEXT_MAJOR: change type to booleanNode and make required or provide default value
39 16
                    ->defaultNull()
40
                    ->beforeNormalization()->ifString()->then(function ($v) {
41
                        // Workaroud to allow detecting if value is not provided. Can be removed when type is switched to booleanNode
42 1
                        return (bool) $v;
43 16
                    })->end()
44 16
                ->end()
45 16
                ->scalarNode('required_locales')->defaultNull()->end() //NEXT_MAJOR: make config required
46 16
                ->scalarNode('default_locale')->defaultNull()->end() //NEXT_MAJOR: make config required
47 16
                ->scalarNode('admin_password')->end()
48 16
                ->scalarNode('admin_user_class')->defaultValue(User::class)->end()
49 16
                ->scalarNode('admin_group_class')->defaultValue(Group::class)->end()
50 16
                ->scalarNode('mail_from_address')->defaultValue('[email protected]')->end()
51 16
                ->scalarNode('mail_from_name')->defaultValue('Kunstmaan CMS')->end()
52 16
                ->booleanNode('enable_new_cms_authentication')->defaultFalse()->end()
53 16
                ->scalarNode('dashboard_route')->end()
54 16
                ->scalarNode('admin_prefix')->defaultValue('admin')->end()
55 16
                ->arrayNode('admin_locales')
56 16
                    ->defaultValue(array('en'))
57 16
                    ->prototype('scalar')->end()
58 16
                ->end()
59 16
                ->arrayNode('session_security')
60 16
                    ->addDefaultsIfNotSet()
61 16
                    ->children()
62 16
                        ->booleanNode('ip_check')->defaultFalse()->end()
63 16
                        ->booleanNode('user_agent_check')->defaultFalse()->end()
64 16
                    ->end()
65 16
                ->end()
66 16
                ->arrayNode('admin_exception_excludes')
67 16
                    ->requiresAtLeastOneElement()
68 16
                    ->prototype('scalar')->end()
69 16
                ->end()
70 16
                ->scalarNode('default_admin_locale')->cannotBeEmpty()->defaultValue('en')->end()
71 16
                ->booleanNode('enable_console_exception_listener')->defaultTrue()->end()
72 16
                ->booleanNode('enable_toolbar_helper')->defaultValue('%kernel.debug%')->end()
73 16
                ->arrayNode('provider_keys')
74 16
                    ->prototype('array')->end()
75 16
                    ->setDeprecated('The "%provider_keys%" is deprecated. Use "toolbar_firewall_names" instead')
76 16
                ->end()
77 16
                ->arrayNode('toolbar_firewall_names')
78 16
                    ->defaultValue(['main'])
79 16
                    ->prototype('array')->end()
80 16
                ->end()
81 16
                ->scalarNode('admin_firewall_name')
82 16
                    ->defaultValue('main')
83 16
                ->end()
84 16
                ->arrayNode('menu_items')
85 16
                    ->defaultValue([])
86 16
                    ->useAttributeAsKey('route', false)
87 16
                    ->prototype('array')
88 16
                        ->children()
89 16
                            ->scalarNode('route')->isRequired()->end()
90 16
                            ->scalarNode('label')->isRequired()->end()
91 16
                            ->scalarNode('role')->defaultNull()->end()
92 16
                            ->arrayNode('params')->defaultValue([])->prototype('scalar')->end()->end()
93 16
                            ->scalarNode('parent')->defaultValue('KunstmaanAdminBundle_modules')->end()
94 16
                        ->end()
95 16
                    ->end()
96 16
                ->end()
97 16
                ->arrayNode('google_signin')
98 16
                    ->addDefaultsIfNotSet()
99 16
                    ->canBeEnabled()
100 16
                    ->beforeNormalization()
101 16
                        ->always()
102
                        ->then(function ($v) {
103 2
                            if ($v === true || (isset($v['enabled']) && $v['enabled'])) {
104 2
                                if (empty($v['client_id']) || empty($v['client_secret'])) {
105 2
                                    throw new InvalidConfigurationException('The "client_id" and "client_secret" settings are required under the "google_signin" group.');
106
                                }
107
                            } else {
108
                                unset($v['client_id'], $v['client_secret'], $v['hosted_domains']);
109
                            }
110
111 1
                            return $v;
112 16
                        })
113 16
                    ->end()
114 16
                    ->children()
115 16
                        ->scalarNode('client_id')->defaultNull()->end()
116 16
                        ->scalarNode('client_secret')->defaultNull()->end()
117 16
                        ->arrayNode('hosted_domains')
118 16
                            ->prototype('array')
119 16
                                ->children()
120 16
                                    ->scalarNode('domain_name')->isRequired()->end()
121 16
                                    ->arrayNode('access_levels')
122 16
                                        ->isRequired()
123 16
                                        ->prototype('scalar')->end()
124 16
                                    ->end()
125 16
                                ->end()
126 16
                            ->end()
127 16
                        ->end()
128 16
                    ->end()
129 16
                ->end()
130 16
                ->arrayNode('password_restrictions')
131 16
                ->addDefaultsIfNotSet()
132 16
                    ->children()
133 16
                        ->integerNode('min_digits')->defaultNull()->end()
134 16
                        ->integerNode('min_uppercase')->defaultNull()->end()
135 16
                        ->integerNode('min_special_characters')->defaultNull()->end()
136 16
                        ->integerNode('min_length')->defaultNull()->end()
137 16
                        ->integerNode('max_length')->defaultNull()->end()
138 16
                    ->end()
139 16
            ->end();
140
141 16
        return $treeBuilder;
142
    }
143
}
144