Completed
Push — dev-master ( ccccd1...cfb4f7 )
by Karol
03:20
created

Configuration   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 95.24%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
c 1
b 0
f 0
dl 0
loc 40
ccs 20
cts 21
cp 0.9524
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfigTreeBuilder() 0 10 1
A addHashidsNode() 0 18 2
1
<?php
2
3
namespace Pgs\HashIdBundle\DependencyInjection;
4
5
use Hashids\Hashids;
6
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
7
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
8
use Symfony\Component\Config\Definition\ConfigurationInterface;
9
10
class Configuration implements ConfigurationInterface
11
{
12
    const ROOT_NAME = 'pgs_hash_id';
13
14
    const NODE_CONVERTER = 'converter';
15
    const NODE_CONVERTER_HASHIDS = 'hashids';
16
    const NODE_CONVERTER_HASHIDS_SALT = 'salt';
17
    const NODE_CONVERTER_HASHIDS_MIN_HASH_LENGTH = 'min_hash_length';
18
    const NODE_CONVERTER_HASHIDS_ALPHABET = 'alphabet';
19
20 6
    public function getConfigTreeBuilder(): TreeBuilder
21
    {
22 6
        $treeBuilder = new TreeBuilder(self::ROOT_NAME);
23 6
        $rootNode = $treeBuilder->getRootNode();
24 6
        $converterNode = (new ArrayNodeDefinition(self::NODE_CONVERTER))->addDefaultsIfNotSet();
25 6
        $rootNode->append($converterNode);
0 ignored issues
show
Bug introduced by
The method append() does not exist on Symfony\Component\Config...\Builder\NodeDefinition. It seems like you code against a sub-type of Symfony\Component\Config...\Builder\NodeDefinition such as Symfony\Component\Config...der\ArrayNodeDefinition. ( Ignorable by Annotation )

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

25
        $rootNode->/** @scrutinizer ignore-call */ 
26
                   append($converterNode);
Loading history...
26
27 6
        $this->addHashidsNode($converterNode);
28
29 6
        return $treeBuilder;
30
    }
31
32 6
    private function addHashidsNode(ArrayNodeDefinition $node): void
33
    {
34 6
        if (!class_exists(Hashids::class)) {
35
            return;
36
        }
37
38
        $node
39 6
            ->children()
40 6
                ->arrayNode(self::NODE_CONVERTER_HASHIDS)->addDefaultsIfNotSet()
41 6
                    ->children()
42 6
                        ->scalarNode(self::NODE_CONVERTER_HASHIDS_SALT)->defaultNull()->end()
43 6
                        ->scalarNode(self::NODE_CONVERTER_HASHIDS_MIN_HASH_LENGTH)->defaultValue(10)->end()
0 ignored issues
show
Bug introduced by
The method scalarNode() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of Symfony\Component\Config...der\NodeParentInterface such as Symfony\Component\Config...ion\Builder\NodeBuilder. ( Ignorable by Annotation )

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

43
                        ->/** @scrutinizer ignore-call */ scalarNode(self::NODE_CONVERTER_HASHIDS_MIN_HASH_LENGTH)->defaultValue(10)->end()
Loading history...
44 6
                        ->scalarNode(self::NODE_CONVERTER_HASHIDS_ALPHABET)
45 6
                            ->defaultValue('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890')
46 6
                        ->end()
47 6
                    ->end()
48 6
                ->end()
49 6
            ->end();
50 6
    }
51
}
52