Configuration::getConfigTreeBuilder()   B
last analyzed

Complexity

Conditions 5
Paths 2

Size

Total Lines 52

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 52
rs 8.7361
c 0
b 0
f 0
cc 5
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
 * This file is part of the PommProject/PommBundle package.
4
 *
5
 * (c) 2014 Grégoire HUBERT <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace PommProject\PommBundle\DependencyInjection;
11
12
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
13
use Symfony\Component\Config\Definition\ConfigurationInterface;
14
15
/**
16
 * Configuration
17
 *
18
 * Configuration manager.
19
 *
20
 * @package PommBundle
21
 * @copyright 2014 Grégoire HUBERT
22
 * @author Nicolas JOSEPH
23
 * @license X11 {@link http://opensource.org/licenses/mit-license.php}
24
 * @see ConfigurationInterface
25
 */
26
class Configuration implements ConfigurationInterface
27
{
28
    /**
29
     * getConfigTreeBuilder
30
     *
31
     * @see ConfigurationInterface
32
     */
33
    public function getConfigTreeBuilder()
34
    {
35
        $treeBuilder = new TreeBuilder('pomm');
36
        $rootNode = method_exists($treeBuilder, 'getRootNode') ? $treeBuilder->getRootNode() : $treeBuilder->root('pomm');
0 ignored issues
show
Bug introduced by
The method root() does not seem to exist on object<Symfony\Component...on\Builder\TreeBuilder>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
37
38
        $rootNode
39
            ->children()
40
                ->arrayNode('configuration')
41
                    ->useAttributeAsKey('key')
42
                    ->requiresAtLeastOneElement()
43
                    ->prototype('array')
44
                        ->children()
45
                            ->scalarNode('dsn')->isRequired()->end()
46
                            ->scalarNode('class:session_builder')
47
                                ->defaultNull()
48
                                ->beforeNormalization()
49
                                    ->always()
50
                                    ->then(function ($v) {
51
                                        @trigger_error('class:session_builder is deprecated since version 2.3 and will be removed in 3.0. Use session_builder config key instead with a service id.', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
52
                                        return $v;
53
                                    })
54
                                ->end()
55
                            ->end()
56
                            ->scalarNode('session_builder')->defaultNull()->end()
57
                            ->scalarNode('pomm:default')->end()
58
                        ->end()
59
                        ->validate()
60
                            ->ifTrue(function ($v) {
61
                                return isset($v['session_builder']) && isset($v['class:session_builder']);
62
                            })
63
                            ->thenInvalid('You cannot use both "session_builder" and "class:session_builder" at the same time.')
64
                        ->end()
65
                        ->beforeNormalization()
66
                            ->always()
67
                            ->then(function ($v) {
68
                                if (!isset($v['session_builder']) && !isset($v['class:session_builder'])) {
69
                                    $v['session_builder'] = 'pomm.model_manager.session_builder';
70
                                }
71
                                return $v;
72
                            })
73
                        ->end()
74
                    ->end()
75
                ->end()
76
                ->arrayNode('logger')
77
                    ->children()
78
                        ->scalarNode('service')->end()
79
                    ->end()
80
                ->end()
81
            ->end();
82
83
        return $treeBuilder;
84
    }
85
}
86