Completed
Push — master ( e7a3c7...2372b5 )
by dan
02:03
created

Configuration::getConfigTreeBuilder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
3
namespace IrishDan\NotificationBundle\DependencyInjection;
4
5
use IrishDan\NotificationBundle\DependencyInjection\Factory\BroadcasterFactory;
6
use IrishDan\NotificationBundle\DependencyInjection\Factory\ChannelFactory;
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
/**
12
 * Class Configuration
13
 *
14
 * @package NotificationBundle\DependencyInjection
15
 */
16
class Configuration implements ConfigurationInterface
17
{
18
    private $defaultAdapterTypes;
19
    private $broadcasters;
20
21
    public function __construct(array $defaultAdapterTypes = [], $broadcasters = [])
22
    {
23
        $this->defaultAdapterTypes = $defaultAdapterTypes;
24
        $this->broadcasters = $broadcasters;
25
    }
26
27
    private function addChannelsSection(ArrayNodeDefinition $node)
28
    {
29
        $channelNodeBuilder = $node
30
            ->children()
31
                ->arrayNode('channels')
32
                ->performNoDeepMerging()
33
                ->children();
34
35
        $factory = new ChannelFactory();
36
        foreach ($this->defaultAdapterTypes as $type) {
37
            $factoryNode = $channelNodeBuilder->arrayNode($type)->canBeUnset();
38
            $factory->addConfiguration($factoryNode, $type);
39
        }
40
    }
41
42
    private function addBroadcastChannelsSection(ArrayNodeDefinition $node)
43
    {
44
        $broadcastNodeBuilder = $node
45
            ->children()
46
                ->arrayNode('broadcasters')
47
                    // ->useAttributeAsKey('name')
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
48
                    ->prototype('array')
49
                    ->performNoDeepMerging()
50
                    ->children()
51
        ;
52
53
        foreach ($this->broadcasters as $name) {
54
            $broadcastNodeBuilder->arrayNode($name)
55
                ->prototype('scalar')->end()
56
                ->end();
57
        }
58
    }
59
60
    /**
61
     * The root configuration for responsive image bundle.
62
     *
63
     * @return TreeBuilder
64
     */
65
    public function getConfigTreeBuilder()
66
    {
67
        $treeBuilder = new TreeBuilder();
68
        $rootNode = $treeBuilder->root('notification');
69
70
71
        $this->addChannelsSection($rootNode);
72
        $this->addBroadcastChannelsSection($rootNode);
73
74
        $rootNode
75
            ->children()
76
            ->end();
77
78
        return $treeBuilder;
79
    }
80
}