Completed
Pull Request — master (#4)
by dan
14:39
created

DependencyInjection/Configuration.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
        'mail',
20
        'logger',
21
        'database',
22
        'nexmo',
23
        'pusher',
24
        'slack',
25
        'custom'
26
    ];
27
    private $broadcasters;
28
29
    public function __construct(array $defaultAdapterTypes = [], $broadcasters = [])
0 ignored issues
show
The parameter $defaultAdapterTypes is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
30
    {
31
        // @TODO: Nothing is passed in so no services defined...
32
        // $this->defaultAdapterTypes = $defaultAdapterTypes;
33
        $this->broadcasters = $broadcasters;
34
    }
35
36
    private function addChannelsSection(ArrayNodeDefinition $node)
37
    {
38
        if (!empty($this->defaultAdapterTypes)) {
39
            $channelNodeBuilder = $node
40
                ->children()
41
                ->booleanNode('use_default_message_subscriber')
42
                    ->defaultTrue()
43
                ->end()
44
                ->arrayNode('channels')
45
                ->performNoDeepMerging()
46
                ->children();
47
48
            $factory = new ChannelFactory();
49
            foreach ($this->defaultAdapterTypes as $type) {
50
                $factoryNode = $channelNodeBuilder->arrayNode($type)->canBeUnset();
51
                $factory->addConfiguration($factoryNode, $type);
52
            }
53
54
            // all for custom channels.
55
            // $factory->addCustomChannel()
56
        }
57
    }
58
59
    private function addBroadcastChannelsSection(ArrayNodeDefinition $node)
60
    {
61
        $broadcastNodeBuilder = $node
62
            ->children()
63
                ->arrayNode('broadcasters')
64
                    // ->useAttributeAsKey('name')
65
                    ->prototype('array')
66
                    ->performNoDeepMerging()
67
                    ->children()
68
        ;
69
70
        foreach ($this->broadcasters as $name) {
71
            $broadcastNodeBuilder->arrayNode($name)
72
                ->prototype('scalar')->end()
73
                ->end();
74
        }
75
    }
76
77
    /**
78
     * The root configuration for responsive image bundle.
79
     *
80
     * @return TreeBuilder
81
     */
82
    public function getConfigTreeBuilder()
83
    {
84
        $treeBuilder = new TreeBuilder();
85
        $rootNode = $treeBuilder->root('notification');
86
87
88
        $this->addChannelsSection($rootNode);
89
        $this->addBroadcastChannelsSection($rootNode);
90
91
        $rootNode
92
            ->children()
93
            ->end();
94
95
        return $treeBuilder;
96
    }
97
}