Completed
Push — master ( 7e13d5...42d7d9 )
by Nikola
03:35
created

Configuration   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 97.73%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 3
dl 0
loc 65
ccs 43
cts 44
cp 0.9773
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B getConfigTreeBuilder() 0 59 7
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 3
    public function getConfigTreeBuilder()
26
    {
27 3
        $treeBuilder = new TreeBuilder();
28 3
        $rootNode = $treeBuilder->root('runopencode_twig_bufferized_template');
29
30
        $rootNode
31 3
            ->fixXmlConfig('node')
32 3
            ->beforeNormalization()
33 3
                ->always()
34
                ->then(function ($value) {
35
36 3
                    if (isset($value['whitelist']) && is_string($value['whitelist'])) {
37 1
                        $value['whitelist'] = [$value['whitelist']];
38
                    }
39
40 3
                    if (isset($value['blacklist']) && is_string($value['blacklist'])) {
41
                        $value['blacklist'] = [$value['blacklist']];
42
                    }
43
44 3
                    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 3
                    return $value;
55 3
                })
56 3
            ->end()
57 3
            ->children()
58 3
                ->integerNode('node_visitor_priority')
59 3
                    ->info('Twig node visitor priority - it should be highest, bufferization should be executed as latest as possible.')
60 3
                    ->defaultValue(10)
61 3
                ->end()
62 3
                ->integerNode('default_execution_priority')
63 3
                    ->info('Default execution priority of bufferized node - if not explicitly provided.')
64 3
                    ->defaultValue(0)
65 3
                ->end()
66 3
                ->arrayNode('whitelist')
67 3
                    ->prototype('scalar')
68 3
                    ->end()
69 3
                ->end()
70 3
                ->arrayNode('blacklist')
71 3
                    ->prototype('scalar')
72 3
                    ->end()
73 3
                ->end()
74 3
                ->arrayNode('nodes')
75 3
                ->useAttributeAsKey('class')
76 3
                    ->prototype('scalar')
77 3
                    ->end()
78 3
                ->end()
79 3
            ->end()
80 3
        ->end();
81
82 3
        return $treeBuilder;
83
    }
84
}
85