Configuration::getConfigTreeBuilder()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 65

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 57
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 65
ccs 57
cts 58
cp 0.9828
rs 8.7636
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2

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
declare(strict_types=1);
4
5
namespace Neo4j\Neo4jBundle\DependencyInjection;
6
7
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
8
use Symfony\Component\Config\Definition\ConfigurationInterface;
9
10
/**
11
 * This class contains the configuration information for the bundle.
12
 *
13
 * This information is solely responsible for how the different configuration
14
 * sections are normalized, and merged.
15
 *
16
 * @author Tobias Nyholm <[email protected]>
17
 */
18
class Configuration implements ConfigurationInterface
19
{
20
    /**
21
     * Whether to use the debug mode.
22
     *
23
     * @see https://github.com/doctrine/DoctrineBundle/blob/v1.5.2/DependencyInjection/Configuration.php#L31-L41
24
     *
25
     * @var bool
26
     */
27
    private $debug;
28
29
    /**
30
     * @param bool $debug
31
     */
32 6
    public function __construct($debug)
33
    {
34 6
        $this->debug = (bool) $debug;
35 6
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 6
    public function getConfigTreeBuilder()
41
    {
42 6
        $treeBuilder = new TreeBuilder('neo4j');
43
        // Keep compatibility with symfony/config < 4.2
44 6
        if (!method_exists($treeBuilder, 'getRootNode')) {
45
            $root = $treeBuilder->root('neo4j');
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...
46
        } else {
47 6
            $root = $treeBuilder->getRootNode();
48
        }
49
50 6
        $root->children()
51 6
            ->arrayNode('profiling')
52 6
                ->addDefaultsIfNotSet()
53 6
                ->treatFalseLike(['enabled' => false])
54 6
                ->treatTrueLike(['enabled' => true])
55 6
                ->treatNullLike(['enabled' => $this->debug])
56 6
                ->info('Extend the web profiler with information about queries.')
57 6
                ->children()
58 6
                    ->booleanNode('enabled')
59 6
                        ->info('Turn the toolbar on or off. Defaults to kernel debug mode.')
60 6
                        ->defaultValue($this->debug)
61 6
                    ->end()
62 6
                ->end()
63 6
            ->end()
64 6
            ->arrayNode('clients')
65 6
                ->requiresAtLeastOneElement()
66 6
                ->useAttributeAsKey('name')
67 6
                ->prototype('array')
68 6
                ->addDefaultsIfNotSet()
69 6
                ->fixXmlConfig('connection')
70 6
                ->children()
71 6
                    ->arrayNode('connections')
72 6
                        ->prototype('scalar')->end()
73 6
                    ->end()
74 6
                ->end()
75 6
            ->end()->end()
76 6
            ->arrayNode('entity_managers')
77 6
                ->requiresAtLeastOneElement()
78 6
                ->useAttributeAsKey('name')
79 6
                ->prototype('array')
80 6
                ->addDefaultsIfNotSet()
81 6
                ->children()
82 6
                    ->scalarNode('client')->defaultValue('default')->end()
83 6
                    ->scalarNode('cache_dir')->defaultNull()->end()
84 6
                ->end()
85 6
            ->end()->end()
86 6
            ->arrayNode('connections')
87 6
                ->isRequired()
88 6
                ->requiresAtLeastOneElement()
89 6
                ->useAttributeAsKey('name')
90 6
                ->prototype('array')
91 6
                ->addDefaultsIfNotSet()
92 6
                ->children()
93 6
                    ->enumNode('scheme')->values(['http', 'bolt'])->defaultValue('bolt')->end()
94 6
                    ->scalarNode('host')->defaultValue('localhost')->end()
95 6
                    ->scalarNode('port')->end()
96 6
                    ->scalarNode('username')->defaultValue('neo4j')->end()
97 6
                    ->scalarNode('password')->defaultValue('neo4j')->end()
98 6
                    ->scalarNode('dsn')->defaultNull()->end()
99 6
                ->end()
100 6
            ->end()
101 6
        ->end();
102
103 6
        return $treeBuilder;
104
    }
105
}
106