Completed
Push — master ( 4407aa...f0730d )
by ANTHONIUS
22s queued 14s
created

Configuration::getConfigTreeBuilder()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 2.0014

Importance

Changes 0
Metric Value
cc 2
eloc 15
nc 2
nop 0
dl 0
loc 22
ccs 13
cts 14
cp 0.9286
crap 2.0014
rs 9.7666
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the DoyoUserBundle project.
5
 *
6
 * (c) Anthonius Munthi <[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 Doyo\UserBundle\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
class Configuration implements ConfigurationInterface
21
{
22 3
    public function getConfigTreeBuilder()
23
    {
24 3
        $treeBuilder = new TreeBuilder('doyo_user');
25
26 3
        if (method_exists($treeBuilder, 'getRootNode')) {
27 3
            $rootNode = $treeBuilder->getRootNode();
28
        } else {
29
            $rootNode = $treeBuilder->root('doyo_user');
0 ignored issues
show
Deprecated Code introduced by
The function Symfony\Component\Config...der\TreeBuilder::root() has been deprecated: since Symfony 4.3, pass the root name to the constructor instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

29
            $rootNode = /** @scrutinizer ignore-deprecated */ $treeBuilder->root('doyo_user');

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

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

Loading history...
30
        }
31
32
        $rootNode
33 3
            ->children()
34 3
                ->scalarNode('db_driver')->defaultValue('orm')->end()
35 3
                ->scalarNode('user_class')->isRequired()->cannotBeEmpty()->end()
36 3
                ->scalarNode('model_manager_name')->defaultValue('default')->end()
37 3
                ->booleanNode('api_platform')->defaultValue(false)->end()
38 3
            ->end();
39
40 3
        $this->addServiceSection($rootNode);
41 3
        $this->addGroupSection($rootNode);
42
43 3
        return $treeBuilder;
44
    }
45
46 3
    private function addServiceSection(ArrayNodeDefinition $node)
47
    {
48
        $node
49 3
            ->addDefaultsIfNotSet()
50 3
            ->children()
51 3
                ->arrayNode('service')
52 3
                    ->addDefaultsIfNotSet()
53 3
                        ->children()
54 3
                            ->scalarNode('email_canonicalizer')->defaultValue('doyo_user.util.canonicalizer.default')->end()
55 3
                            ->scalarNode('username_canonicalizer')->defaultValue('doyo_user.util.canonicalizer.default')->end()
0 ignored issues
show
Bug introduced by
The method scalarNode() 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

55
                            ->/** @scrutinizer ignore-call */ scalarNode('username_canonicalizer')->defaultValue('doyo_user.util.canonicalizer.default')->end()
Loading history...
56 3
                            ->scalarNode('password_updater')->defaultValue('doyo_user.util.password_updater.default')->end()
57 3
                            ->scalarNode('user_manager')->defaultValue('doyo_user.user_manager.default')->end()
58 3
                        ->end()
59 3
                    ->end()
60 3
                ->end()
61 3
            ->end();
62
    }
63
64 3
    private function addGroupSection(ArrayNodeDefinition $node)
65
    {
66
        $node
67 3
            ->children()
68 3
                ->arrayNode('group')
69 3
                    ->canBeUnset()
70 3
                    ->children()
71 3
                        ->scalarNode('group_class')->isRequired()->cannotBeEmpty()->end()
72 3
                        ->scalarNode('group_manager')->defaultValue('doyo_user.group_manager.default')->end()
73 3
                    ->end()
74 3
                ->end()
75 3
            ->end();
76
    }
77
}
78