Completed
Push — master ( 2e004f...db8ff8 )
by dan
01:41
created

ChannelFactory::create()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 27
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 27
rs 8.8571
cc 2
eloc 14
nc 2
nop 3
1
<?php
2
3
namespace IrishDan\NotificationBundle\DependencyInjection\Factory;
4
5
use Symfony\Component\DependencyInjection\ContainerBuilder;
6
use Symfony\Component\DependencyInjection\Definition;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
class ChannelFactory
10
{
11
    public function create(ContainerBuilder $container, $channel, array $config)
12
    {
13
        $definition = new Definition();
14
        $definition->setClass('IrishDan\NotificationBundle\Channel\DirectChannel');
15
        $definition->setArguments(
16
            [
17
                '%notification.channel.' . $channel . '.configuration%',
18
                $channel,
19
            ]
20
        );
21
22
        $adapter = new Reference('notification.adapter.' . $channel);
23
        $eventDispatcher = new Reference('event_dispatcher');
24
25
        $definition->setMethodCalls(
26
            [
27
                ['setAdapter', [$adapter]],
28
                ['setEventDispatcher', [$eventDispatcher]],
29
            ]
30
        );
31
32
        if (!empty($config['direct_dispatch'])) {
33
            $definition->addMethodCall('setDispatchToEvent', [false]);
34
        }
35
36
        $container->setDefinition('notification.channel.' . $channel, $definition);
37
    }
38
}
39