Passed
Push — master ( b08524...781099 )
by Martin
03:59
created

Configuration   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
c 1
b 0
f 0
dl 0
loc 42
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createSubscriberNode() 0 19 2
A getConfigTreeBuilder() 0 14 2
A isBeforeSymfony4() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Alpha\VisitorTrackingBundle\DependencyInjection;
6
7
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
8
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
9
use Symfony\Component\Config\Definition\ConfigurationInterface;
10
11
class Configuration implements ConfigurationInterface
12
{
13
    public function getConfigTreeBuilder(): TreeBuilder
14
    {
15
        if ($this->isBeforeSymfony4()) {
16
            $treeBuilder = new TreeBuilder();
17
            $rootNode = $treeBuilder->root('alpha_visitor_tracking');
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

17
            $rootNode = /** @scrutinizer ignore-deprecated */ $treeBuilder->root('alpha_visitor_tracking');

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...
18
        } else {
19
            $treeBuilder = new TreeBuilder('alpha_visitor_tracking');
20
            $rootNode = $treeBuilder->getRootNode();
21
        }
22
        \assert($rootNode instanceof ArrayNodeDefinition);
23
24
        $rootNode->append($this->createSubscriberNode());
25
26
        return $treeBuilder;
27
    }
28
29
    private function createSubscriberNode(): ArrayNodeDefinition
30
    {
31
        if ($this->isBeforeSymfony4()) {
32
            $treeBuilder = new TreeBuilder();
33
            $rootNode = $treeBuilder->root('session_subscriber');
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

33
            $rootNode = /** @scrutinizer ignore-deprecated */ $treeBuilder->root('session_subscriber');

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...
34
        } else {
35
            $treeBuilder = new TreeBuilder('session_subscriber');
36
            $rootNode = $treeBuilder->getRootNode();
37
        }
38
        \assert($rootNode instanceof ArrayNodeDefinition);
39
40
        $rootNode->addDefaultsIfNotSet();
41
42
        $rootNode->children()->arrayNode('firewall_blacklist')
43
            ->defaultValue([])
44
            ->prototype('scalar')
45
            ->cannotBeEmpty();
46
47
        return $rootNode;
48
    }
49
50
    private function isBeforeSymfony4(): bool
51
    {
52
        return !\method_exists(TreeBuilder::class, 'getRootNode');
53
    }
54
}
55