Passed
Pull Request — master (#7)
by Dmitry
04:27
created

Configuration::addServiceSection()   A

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 2
    public function getConfigTreeBuilder()
16
    {
17 2
        $builder = new TreeBuilder();
18 2
        $rootNode = $builder->root('sb_queue');
19
20 2
        $this->addServiceSection($rootNode);
21 2
        $this->addSettingsSection($rootNode);
22 2
        $this->addStoragesSection($rootNode);
23
24 2
        return $builder;
25
    }
26
27
    /**
28
     * Adds the sb_queue.service configuration.
29
     *
30
     * @param ArrayNodeDefinition $node
31
     */
32 2
    private function addServiceSection(ArrayNodeDefinition $node)
33
    {
34
        $node
35 2
            ->children()
36 2
                ->arrayNode('service')
37 2
                    ->addDefaultsIfNotSet()
38 2
                    ->children()
39 2
                        ->scalarNode('class')
40 2
                            ->defaultValue(Service\Queue::class)->cannotBeEmpty()
41 2
                        ->end()
42 2
                        ->scalarNode('alias')
43 2
                            ->defaultValue('queue')->cannotBeEmpty()
44 2
                        ->end()
45 2
                        ->scalarNode('storage')
46 2
                            ->defaultValue('redis')->cannotBeEmpty()
47 2
                        ->end()
48 2
                    ->end()
49 2
                ->end()
50 2
            ->end();
51 2
    }
52
53
    /**
54
     * Adds the sb_queue.settings configuration.
55
     *
56
     * @param ArrayNodeDefinition $node
57
     */
58 2
    private function addSettingsSection(ArrayNodeDefinition $node)
59
    {
60
        $node
61 2
            ->children()
62 2
                ->arrayNode('settings')
63 2
                    ->addDefaultsIfNotSet()
64 2
                    ->children()
65 2
                        ->scalarNode('queue_default_name')
66 2
                            ->defaultValue('queue:default')->cannotBeEmpty()
67 2
                        ->end()
68 2
                    ->end()
69 2
                ->end()
70 2
            ->end();
71 2
    }
72
73
    /**
74
     * Adds the sb_queue.storages configuration.
75
     *
76
     * @param ArrayNodeDefinition $node
77
     */
78 2
    private function addStoragesSection(ArrayNodeDefinition $node)
79
    {
80
        $node
81 2
            ->children()
82 2
                ->arrayNode('storages')
83 2
                    ->addDefaultChildrenIfNoneSet('redis')
84 2
                    ->requiresAtLeastOneElement()
85 2
                    ->useAttributeAsKey('redis')
86 2
                    ->prototype('array')
87 2
                        ->children()
88 2
                            ->scalarNode('class')
89 2
                                ->defaultValue(Service\Storage\RedisStorage::class)->cannotBeEmpty()
90 2
                            ->end()
91 2
                            ->scalarNode('client')
92 2
                                ->defaultValue('sb_redis.client.default')->cannotBeEmpty()
93 2
                            ->end()
94 2
                        ->end()
95 2
                    ->end()
96 2
                ->end()
97 2
            ->end();
98 2
    }
99
}
100