Configuration::isBeforeSymfony4()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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