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

DependencyInjection/Factory/BroadcasterFactory.php (3 issues)

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\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
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...
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