Configuration   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 6
Bugs 0 Features 0
Metric Value
eloc 34
c 6
b 0
f 0
dl 0
loc 52
ccs 30
cts 35
cp 0.8571
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A getConfigTreeBuilder() 0 45 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Knp\DictionaryBundle\DependencyInjection;
6
7
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
8
use Symfony\Component\Config\Definition\ConfigurationInterface;
9
10
final class Configuration implements ConfigurationInterface
11
{
12
    /**
13
     * @var string
14
     */
15
    private const CONFIG_NAME = 'knp_dictionary';
16
17 1
    public function getConfigTreeBuilder(): TreeBuilder
18
    {
19 1
        $treeBuilder    = new TreeBuilder(self::CONFIG_NAME);
20 1
        $nodeDefinition = $treeBuilder->getRootNode();
21 1
22 1
        $nodeDefinition
23
            ->children()
24
            ->arrayNode('dictionaries')
25
                ->useAttributeAsKey('name')
26 1
                    ->prototype('array')
27 1
                        ->beforeNormalization()
28 1
                            ->always()
29 1
                            ->then(static function ($values) {
30 1
                                if (false === \array_key_exists('type', $values)) {
31 1
                                    if (false === \array_key_exists('content', $values)) {
32 1
                                        return ['type' => 'value', 'content' => $values];
33
                                    }
34
35
                                    return array_merge($values, ['type' => 'value']);
36
                                }
37
38
                                /**
39
                                 * @var non-empty-array<mixed> $values
40
                                 */
41
                                return $values;
42 1
                            })
43 1
                        ->end()
44 1
                        ->children()
45 1
                            ->scalarNode('type')->defaultValue('value')->end()
46 1
                            ->scalarNode('extends')->end()
47 1
                            ->arrayNode('dictionaries')
48 1
                                ->normalizeKeys(false)->prototype('scalar')->end()
49 1
                            ->end()
50 1
                            ->arrayNode('content')
51 1
                                ->normalizeKeys(false)->prototype('scalar')->end()
52 1
                            ->end()
53 1
                            ->scalarNode('service')->end()
54 1
                            ->scalarNode('method')->end()
55 1
                        ->end()
56 1
                    ->end()
57 1
                ->end()
58 1
            ->end()
59
        ;
60
61 1
        return $treeBuilder;
62
    }
63
}
64