Configuration::getConfigTreeBuilder()   B
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 70
Code Lines 62

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 63
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 62
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 70
ccs 63
cts 63
cp 1
crap 3
rs 8.829

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace DoL\LdapBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
7
use Symfony\Component\Config\Definition\ConfigurationInterface;
8
9
/**
10
 * This is the class that validates and merges configuration from your app/config files.
11
 *
12
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
13
 *
14
 * @author DarwinOnLine
15
 * @author Maks3w
16
 *
17
 * @see https://github.com/DarwinOnLine/DoLLdapBundle
18
 */
19
class Configuration implements ConfigurationInterface
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24 6
    public function getConfigTreeBuilder()
25
    {
26 6
        $treeBuilder = new TreeBuilder();
27 6
        $rootNode = $treeBuilder->root('dol_ldap');
28
29
        $rootNode
30 6
            ->children()
31 6
                ->arrayNode('domains')
32 6
                    ->useAttributeAsKey('id')
33 6
                    ->prototype('array')
34 6
                        ->children()
35 6
                            ->arrayNode('driver')
36 6
                                ->children()
37 6
                                    ->scalarNode('host')->isRequired()->cannotBeEmpty()->end()
38 6
                                    ->scalarNode('port')->defaultValue(389)->end()
39 6
                                    ->scalarNode('useStartTls')->defaultFalse()->end()
40 6
                                    ->scalarNode('useSsl')->defaultFalse()->end()
41 6
                                    ->scalarNode('username')->end()
42 6
                                    ->scalarNode('password')->end()
43 6
                                    ->scalarNode('bindRequiresDn')->defaultFalse()->end()
44 6
                                    ->scalarNode('baseDn')->end()
45 6
                                    ->scalarNode('accountCanonicalForm')->end()
46 6
                                    ->scalarNode('accountDomainName')->end()
47 6
                                    ->scalarNode('accountDomainNameShort')->end()
48 6
                                    ->scalarNode('accountFilterFormat')->end()
49 6
                                    ->scalarNode('allowEmptyPassword')->end()
50 6
                                    ->scalarNode('optReferrals')->end()
51 6
                                    ->scalarNode('tryUsernameSplit')->end()
52 6
                                    ->scalarNode('networkTimeout')->end()
53 6
                                ->end()
54 6
                                ->validate()
55
                                    ->ifTrue(function ($v) {
56 6
                                        return $v['useSsl'] && $v['useStartTls'];
57 6
                                    })
58 6
                                    ->thenInvalid('The useSsl and useStartTls options are mutually exclusive.')
59 6
                                ->end()
60 6
                            ->end()
61 6
                            ->arrayNode('user')
62 6
                                ->children()
63 6
                                    ->scalarNode('baseDn')->isRequired()->cannotBeEmpty()->end()
64 6
                                    ->scalarNode('filter')->defaultValue('')->end()
65 6
                                    ->scalarNode('usernameAttribute')->defaultValue('uid')->end()
66 6
                                    ->arrayNode('attributes')
67 6
                                        ->defaultValue(array(
68
                                            array(
69 6
                                                'ldap_attr' => 'uid',
70 6
                                                'user_method' => 'setUsername', ),
71 6
                                            ))
72 6
                                        ->prototype('array')
73 6
                                            ->children()
74 6
                                                ->scalarNode('ldap_attr')->isRequired()->cannotBeEmpty()->end()
75 6
                                                ->scalarNode('user_method')->isRequired()->cannotBeEmpty()->end()
76 6
                                            ->end()
77 6
                                        ->end()
78 6
                                    ->end()
79 6
                                ->end()
80 6
                            ->end()
81 6
                        ->end()
82 6
                    ->validate()
83 6
                        ->ifTrue(function ($v) {
84 5
                            return $v['driver']['useSsl'] && $v['driver']['useStartTls'];
85 6
                        })
86 6
                        ->thenInvalid('The useSsl and useStartTls options are mutually exclusive.')
87 6
                    ->end()
88 6
                ->end()
89 6
            ->end();
90
91 6
        $this->addServiceSection($rootNode);
92
93 6
        return $treeBuilder;
94
    }
95
96 6
    private function addServiceSection(ArrayNodeDefinition $node)
97
    {
98
        $node
99 6
                ->addDefaultsIfNotSet()
100 6
                    ->children()
101 6
                        ->arrayNode('service')
102 6
                            ->addDefaultsIfNotSet()
103 6
                            ->children()
104 6
                                ->scalarNode('user_hydrator')->defaultValue('dol_ldap.user_hydrator.default')->end()
105 6
                                ->scalarNode('ldap_manager')->defaultValue('dol_ldap.ldap_manager.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

105
                                ->/** @scrutinizer ignore-call */ scalarNode('ldap_manager')->defaultValue('dol_ldap.ldap_manager.default')->end()
Loading history...
106 6
                                ->scalarNode('ldap_driver')->defaultValue('dol_ldap.ldap_driver.zend')->end()
107 6
                            ->end()
108 6
                        ->end()
109 6
                    ->end()
110 6
                ->end();
111 6
    }
112
}
113