Completed
Push — dev-master ( bd06c4...a7b6e6 )
by Karol
03:06
created

Configuration   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 93.1%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 36
c 2
b 0
f 0
dl 0
loc 51
ccs 27
cts 29
cp 0.931
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfigTreeBuilder() 0 19 2
A addHashidsConverterNode() 0 20 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
        if (method_exists($treeBuilder, 'getRootNode')) {
24 6
            $rootNode = $treeBuilder->getRootNode();
25
        } else {
26
            // BC layer for symfony/config 4.1 and older
27
            $rootNode = $treeBuilder->root(self::ROOT_NAME);
0 ignored issues
show
Deprecated Code introduced by
The function Symfony\Component\Config...der\TreeBuilder::root() has been deprecated: since Symfony 4.3, pass the root name to the constructor instead ( Ignorable by Annotation )

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

27
            $rootNode = /** @scrutinizer ignore-deprecated */ $treeBuilder->root(self::ROOT_NAME);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
28
        }
29
        $rootNode
30 6
            ->children()
31 6
                ->arrayNode(self::NODE_CONVERTER)->addDefaultsIfNotSet()
32 6
                    ->children()
33 6
                        ->append($this->addHashidsConverterNode())
34 6
                    ->end()
35 6
                ->end()
36 6
            ->end();
37
38 6
        return $treeBuilder;
39
    }
40
41 6
    private function addHashidsConverterNode(): ArrayNodeDefinition
42
    {
43 6
        $node = new ArrayNodeDefinition(self::NODE_CONVERTER_HASHIDS);
44
45 6
        if (!class_exists(Hashids::class)) {
46
            return $node;
47
        }
48
49 6
        return $node->addDefaultsIfNotSet()
50 6
                ->children()
51 6
                    ->scalarNode(self::NODE_CONVERTER_HASHIDS_SALT)
52 6
                        ->defaultNull()
53 6
                    ->end()
54 6
                    ->scalarNode(self::NODE_CONVERTER_HASHIDS_MIN_HASH_LENGTH)
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

54
                    ->/** @scrutinizer ignore-call */ scalarNode(self::NODE_CONVERTER_HASHIDS_MIN_HASH_LENGTH)
Loading history...
55 6
                        ->defaultValue(10)
56 6
                    ->end()
57 6
                    ->scalarNode(self::NODE_CONVERTER_HASHIDS_ALPHABET)
58 6
                        ->defaultValue('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890')
59 6
                    ->end()
60 6
                ->end();
61
    }
62
}
63