Configuration::getConfigTreeBuilder()   B
last analyzed

Complexity

Conditions 7
Paths 1

Size

Total Lines 59
Code Lines 45

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 44
CRAP Score 7

Importance

Changes 0
Metric Value
dl 0
loc 59
ccs 44
cts 44
cp 1
rs 7.5346
c 0
b 0
f 0
cc 7
eloc 45
nc 1
nop 0
crap 7

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 Twig Bufferized Template package, an RunOpenCode project.
4
 *
5
 * (c) 2017 RunOpenCode
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 RunOpenCode\Twig\BufferizedTemplate\Bridge\Symfony\DependencyInjection;
11
12
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
13
use Symfony\Component\Config\Definition\ConfigurationInterface;
14
15
/**
16
 * Class Configuration
17
 *
18
 * @package RunOpenCode\Twig\BufferizedTemplate\Bridge\Symfony\DependencyInjection
19
 */
20
class Configuration implements ConfigurationInterface
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25 4
    public function getConfigTreeBuilder()
26
    {
27 4
        $treeBuilder = new TreeBuilder();
28 4
        $rootNode = $treeBuilder->root('runopencode_twig_bufferized_template');
29
30
        $rootNode
31 4
            ->fixXmlConfig('node')
32 4
            ->beforeNormalization()
33 4
                ->always()
34
                ->then(function ($value) {
35
36 4
                    if (isset($value['whitelist']) && is_string($value['whitelist'])) {
37 1
                        $value['whitelist'] = [$value['whitelist']];
38
                    }
39
40 4
                    if (isset($value['blacklist']) && is_string($value['blacklist'])) {
41 1
                        $value['blacklist'] = [$value['blacklist']];
42
                    }
43
44 4
                    if (isset($value['node'])) {
45
46 1
                        $value['node'] = array_map(function($node) {
47 1
                            if (!isset($node['value'])) {
48 1
                                $node['value'] = null;
49
                            }
50 1
                            return $node;
51 1
                        }, $value['node']);
52
                    }
53
54 4
                    return $value;
55 4
                })
56 4
            ->end()
57 4
            ->children()
58 4
                ->integerNode('node_visitor_priority')
59 4
                    ->info('Twig node visitor priority - it should be highest, bufferization should be executed as latest as possible.')
60 4
                    ->defaultValue(10)
61 4
                ->end()
62 4
                ->integerNode('default_execution_priority')
63 4
                    ->info('Default execution priority of bufferized node - if not explicitly provided.')
64 4
                    ->defaultValue(0)
65 4
                ->end()
66 4
                ->arrayNode('whitelist')
67 4
                    ->prototype('scalar')
68 4
                    ->end()
69 4
                ->end()
70 4
                ->arrayNode('blacklist')
71 4
                    ->prototype('scalar')
72 4
                    ->end()
73 4
                ->end()
74 4
                ->arrayNode('nodes')
75 4
                ->useAttributeAsKey('class')
76 4
                    ->prototype('scalar')
77 4
                    ->end()
78 4
                ->end()
79 4
            ->end()
80 4
        ->end();
81
82 4
        return $treeBuilder;
83
    }
84
}
85