Configuration::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
namespace Dkplus\CsrfApiUnprotectionBundle\DependencyInjection;
3
4
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
5
use Symfony\Component\Config\Definition\ConfigurationInterface;
6
7
final class Configuration implements ConfigurationInterface
8
{
9
    /** @var string */
10
    private $treeRootName;
11
12
    /**
13
     * @param string $treeRootName
14
     */
15 11
    public function __construct($treeRootName)
16
    {
17 11
        $this->treeRootName = $treeRootName;
18 11
    }
19
20
    /**
21
     * Generates the configuration tree builder.
22
     *
23
     * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
24
     */
25 10
    public function getConfigTreeBuilder()
26
    {
27 10
        $treeBuilder = new TreeBuilder();
28 10
        $treeBuilder->root($this->treeRootName)
29 10
            ->children()
30 10
            ->arrayNode('rules')
31 10
                ->addDefaultsIfNotSet()
32 10
                ->children()
33 10
                ->arrayNode('match_uri')
34 10
                    ->beforeNormalization()
35 10
                        ->ifString()
36 10
                        ->then(function ($value) {
37 1
                            return [$value];
38 10
                        })
39 10
                    ->end()
40 10
                    ->isRequired()
41 10
                    ->defaultValue(['#^(/app(_[a-zA-Z]*)?.php)?/api/#'])
42 10
                    ->prototype('scalar')->cannotBeEmpty()->end()
43 10
                ->end()
44 10
            ->end();
45
46 10
        return $treeBuilder;
47
    }
48
}
49