Configuration::addServiceSection()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 18
cts 18
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 18
nc 1
nop 1
crap 1
1
<?php
2
3
namespace SymfonyBundles\QueueBundle\DependencyInjection;
4
5
use SymfonyBundles\QueueBundle\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_queue');
19
20 3
        $this->addServiceSection($rootNode);
21 3
        $this->addSettingsSection($rootNode);
22 3
        $this->addStoragesSection($rootNode);
23
24 3
        return $builder;
25
    }
26
27
    /**
28
     * Adds the sb_queue.service configuration.
29
     *
30
     * @param ArrayNodeDefinition $node
31
     */
32 3
    private function addServiceSection(ArrayNodeDefinition $node)
33
    {
34
        $node
35 3
            ->children()
36 3
                ->arrayNode('service')
37 3
                    ->addDefaultsIfNotSet()
38 3
                    ->children()
39 3
                        ->scalarNode('class')
40 3
                            ->defaultValue(Service\Queue::class)->cannotBeEmpty()
41 3
                        ->end()
42 3
                        ->scalarNode('alias')
43 3
                            ->defaultValue('queue')->cannotBeEmpty()
44 3
                        ->end()
45 3
                        ->scalarNode('storage')
46 3
                            ->defaultValue('redis')->cannotBeEmpty()
47 3
                        ->end()
48 3
                    ->end()
49 3
                ->end()
50 3
            ->end();
51 3
    }
52
53
    /**
54
     * Adds the sb_queue.settings configuration.
55
     *
56
     * @param ArrayNodeDefinition $node
57
     */
58 3
    private function addSettingsSection(ArrayNodeDefinition $node)
59
    {
60
        $node
61 3
            ->children()
62 3
                ->arrayNode('settings')
63 3
                    ->addDefaultsIfNotSet()
64 3
                    ->children()
65 3
                        ->scalarNode('queue_default_name')
66 3
                            ->defaultValue('queue:default')->cannotBeEmpty()
67 3
                        ->end()
68 3
                    ->end()
69 3
                ->end()
70 3
            ->end();
71 3
    }
72
73
    /**
74
     * Adds the sb_queue.storages configuration.
75
     *
76
     * @param ArrayNodeDefinition $node
77
     */
78 3
    private function addStoragesSection(ArrayNodeDefinition $node)
79
    {
80
        $node
81 3
            ->children()
82 3
                ->arrayNode('storages')
83 3
                    ->addDefaultChildrenIfNoneSet('redis')
84 3
                    ->requiresAtLeastOneElement()
85 3
                    ->useAttributeAsKey('redis')
86 3
                    ->prototype('array')
87 3
                        ->children()
88 3
                            ->scalarNode('class')
89 3
                                ->defaultValue(Service\Storage\RedisStorage::class)->cannotBeEmpty()
90 3
                            ->end()
91 3
                            ->scalarNode('client')
92 3
                                ->defaultValue('sb_redis.client.default')->cannotBeEmpty()
93 3
                            ->end()
94 3
                        ->end()
95 3
                    ->end()
96 3
                ->end()
97 3
            ->end();
98 3
    }
99
}
100