BroadcasterFactory::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 9.472
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
3
namespace IrishDan\NotificationBundle\DependencyInjection\Factory;
4
5
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Definition;
8
use Symfony\Component\DependencyInjection\Reference;
9
10
class BroadcasterFactory
11
{
12
    public function create(ContainerBuilder $container, $name, array $config)
13
    {
14
        $type = array_keys($config)[0];
15
        $parameterName = 'notification.broadcast.config.' . $name;
16
        $serviceName = 'notification.broadcast.' . $name;
17
18
        $channelFactory = new ChannelFactory();
19
        $channelServiceName = $channelFactory->create($container, $name, $config[$type], $type);
20
21
        // Create the configuration as a parameter.
22
        $container->setParameter($parameterName, $config[$type]);
23
24
        // Create the broadcast service
25
        $definition = new Definition();
26
        $definition->setClass('IrishDan\NotificationBundle\Broadcast\Broadcaster');
27
        $definition->setArguments(
28
            [
29
                new Reference('notification.broadcast.notifiable'),
30
                new Reference($channelServiceName),
31
                '%' . $parameterName . '%',
32
            ]
33
        );
34
35
        $container->setDefinition($serviceName, $definition);
36
37
        // Add the broadcast to the notification manager.
38
        $container->findDefinition('notification.manager')->addMethodCall('setBroadcaster', [$name, new Reference($serviceName)]);
39
    }
40
41
    public function addConfiguration(NodeDefinition $node, $type)
0 ignored issues
show
Unused Code introduced by
The parameter $node 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...
Unused Code introduced by
The parameter $type 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...
42
    {
43
        // var_dump($node->getNode());
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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...
44
    }
45
}
46