Passed
Pull Request — master (#149)
by Pierre
03:06
created

Configuration::getConfigTreeBuilder()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 45
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 30
CRAP Score 4.0466

Importance

Changes 5
Bugs 0 Features 0
Metric Value
cc 4
eloc 34
c 5
b 0
f 0
nc 2
nop 0
dl 0
loc 45
ccs 30
cts 35
cp 0.8571
crap 4.0466
rs 9.376
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
        $builder  = new TreeBuilder(self::CONFIG_NAME);
20 1
        $rootNode = method_exists($builder, 'getRootNode')
21 1
            ? $builder->getRootNode()
22 1
            : $builder->root(self::CONFIG_NAME)
0 ignored issues
show
Bug introduced by
The method root() does not exist on Symfony\Component\Config...ion\Builder\TreeBuilder. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

22
            : $builder->/** @scrutinizer ignore-call */ root(self::CONFIG_NAME)

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...
23
        ;
24
25
        $rootNode
26 1
            ->children()
27 1
            ->arrayNode('dictionaries')
28 1
                ->useAttributeAsKey('name')
29 1
                    ->prototype('array')
30 1
                        ->beforeNormalization()
31 1
                            ->always()
32 1
                            ->then(function ($values) {
33
                                if (false === \array_key_exists('type', $values)) {
34
                                    if (false === \array_key_exists('content', $values)) {
35
                                        return ['type' => 'value', 'content' => $values];
36
                                    }
37
38
                                    return array_merge($values, ['type' => 'value']);
39
                                }
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 $builder;
62
    }
63
}
64