Configuration::addRootSection()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 17
cts 17
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 17
nc 1
nop 1
crap 1
1
<?php
2
3
namespace SymfonyBundles\EventQueueBundle\DependencyInjection;
4
5
use SymfonyBundles\EventQueueBundle\Service;
6
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
7
use Symfony\Component\Config\Definition\ConfigurationInterface;
8
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
9
10
class Configuration implements ConfigurationInterface
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15 3
    public function getConfigTreeBuilder()
16
    {
17 3
        $builder = new TreeBuilder();
18 3
        $rootNode = $builder->root('sb_event_queue');
19
20 3
        $this->addRootSection($rootNode);
21 3
        $this->addClassSection($rootNode);
22
23 3
        return $builder;
24
    }
25
26
    /**
27
     * Adds root node configuration.
28
     *
29
     * @param ArrayNodeDefinition $node
30
     */
31 3
    private function addRootSection(ArrayNodeDefinition $node)
32
    {
33
        $node
34 3
            ->addDefaultsIfNotSet()
35 3
            ->children()
36 3
                ->scalarNode('service_name')
37 3
                    ->defaultValue('event_queue')
38 3
                    ->cannotBeEmpty()
39 3
                ->end()
40 3
                ->scalarNode('default_name')
41 3
                    ->defaultValue('event:default')
42 3
                    ->cannotBeEmpty()
43 3
                ->end()
44 3
                ->scalarNode('storage_path')
45 3
                    ->defaultValue('%kernel.cache_dir%/event-queue-daemon.%s.pid')
46 3
                    ->cannotBeEmpty()
47 3
                ->end()
48 3
            ->end();
49 3
    }
50
51
    /**
52
     * Adds the sb_event_queue.class configuration.
53
     *
54
     * @param ArrayNodeDefinition $node
55
     */
56 3
    private function addClassSection(ArrayNodeDefinition $node)
57
    {
58
        $node
59 3
            ->children()
60 3
                ->arrayNode('class')
61 3
                    ->addDefaultsIfNotSet()
62 3
                    ->children()
63 3
                        ->scalarNode('dispatcher')
64 3
                            ->defaultValue(Service\Dispatcher::class)
65 3
                            ->cannotBeEmpty()
66 3
                        ->end()
67 3
                    ->end()
68 3
                ->end()
69 3
            ->end();
70 3
    }
71
}
72