Completed
Pull Request — master (#27)
by
unknown
01:05
created

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 55

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 55
rs 8.9818
c 0
b 0
f 0
cc 2
nc 2
nop 0

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
/*
4
 * This file is part of the EoHoneypotBundle package.
5
 *
6
 * (c) Eymen Gunay <[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
namespace Eo\HoneypotBundle\DependencyInjection;
13
14
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
15
use Symfony\Component\Config\Definition\ConfigurationInterface;
16
17
/**
18
 * This is the class that validates and merges configuration from your app/config files
19
 *
20
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
21
 */
22
class Configuration implements ConfigurationInterface
23
{
24
    /**
25
     * {@inheritDoc}
26
     */
27
    public function getConfigTreeBuilder()
28
    {
29
        if (\method_exists(TreeBuilder::class, 'getRootNode')) {
30
            // Symfony 4.1+
31
            $treeBuilder = new TreeBuilder('eo_honeypot');
32
            $rootNode = $treeBuilder->getRootNode();
33
        } else {
34
            // Symfony <= 4.0
35
            $treeBuilder = new TreeBuilder();
36
            $rootNode = $treeBuilder->root('eo_honeypot');
37
        }
38
39
        $rootNode
40
            ->children()
41
                ->arrayNode('redirect')
42
                    ->canBeEnabled()
43
                    ->addDefaultsIfNotSet()
44
                    ->children()
45
                        ->scalarNode('url')->defaultNull()->end()
46
                        ->scalarNode('route')->defaultNull()->end()
47
                        ->arrayNode('route_parameters')
48
                            ->useAttributeAsKey('name')
49
                            ->prototype('scalar')->end()
50
                        ->end()
51
                    ->end()
52
                ->end()
53
                ->arrayNode('storage')
54
                    ->addDefaultsIfNotSet()
55
                    ->children()
56
                        ->arrayNode('database')
57
                            ->canBeEnabled()
58
                            ->children()
59
                                ->scalarNode('class')->defaultValue('ApplicationEoHoneypotBundle:HoneypotPrey')->end()
60
                                ->scalarNode('driver')
61
                                    ->defaultValue('mongodb')
62
                                    ->validate()
63
                                    ->ifNotInArray(array('orm', 'mongodb'))
64
                                        ->thenInvalid('Invalid database driver "%s"')
65
                                    ->end()
66
                                ->end()
67
                            ->end()
68
                        ->end()
69
                        ->arrayNode('file')
70
                            ->canBeEnabled()
71
                            ->children()
72
                                ->scalarNode('output')->defaultValue('/var/log/honeypot.log')->end()
73
                            ->end()
74
                        ->end()
75
                    ->end()
76
                ->end()
77
            ->end()
78
        ;
79
80
        return $treeBuilder;
81
    }
82
}
83