Completed
Pull Request — master (#3)
by Alessandro
04:40
created

FacileCrossbarHTTPPublisherExtension   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 63
ccs 30
cts 33
cp 0.9091
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addFactoryToContainer() 0 9 1
A load() 0 7 1
B loadConnections() 0 30 4
1
<?php
2
3
namespace Facile\CrossbarHTTPPublisherBundle\DependencyInjection;
4
5
use Symfony\Component\DependencyInjection\ContainerBuilder;
6
use Symfony\Component\DependencyInjection\Definition;
7
use Symfony\Component\DependencyInjection\Reference;
8
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
9
10
/**
11
 * Class FacileCrossbarHTTPPublisherExtension
12
 * @package Facile\CrossbarHTTPPublisherBundle\DependencyInjection
13
 */
14
class FacileCrossbarHTTPPublisherExtension extends Extension
15
{
16
    /**
17
     * {@inheritDoc}
18
     */
19 1
    public function load(array $config, ContainerBuilder $container)
20
    {
21 1
        $configuration = new Configuration();
22 1
        $config = $this->processConfiguration($configuration, $config);
23
24 1
        $this->loadConnections($container, $config);
25 1
    }
26
27
    /**
28
     * Registers publisher services in container
29
     * @param ContainerBuilder $container
30
     * @param array $config
31
     */
32 1
    private function loadConnections(ContainerBuilder $container, array $config)
33
    {
34 1
        $factoryName = $this->addFactoryToContainer($container);
35 1
        $genericDefinition = new Definition('Facile\CrossbarHTTPPublisherBundle\Publisher\Publisher');
36 1
        if (method_exists($genericDefinition, 'setFactory')) {
37 1
            $genericDefinition->setFactory([new Reference($factoryName), 'createPublisher']);
38
        } else {
39
            $genericDefinition->setFactoryService($factoryName);
1 ignored issue
show
Bug introduced by
The method setFactoryService() does not exist on Symfony\Component\DependencyInjection\Definition. Did you maybe mean setFactory()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
40
            $genericDefinition->setFactoryMethod('createPublisher');
1 ignored issue
show
Bug introduced by
The method setFactoryMethod() does not exist on Symfony\Component\DependencyInjection\Definition. Did you maybe mean setFactory()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
41
        }
42
43 1
        foreach ($config['connections'] as $key => $connection) {
44 1
            $protocol = $connection['protocol'];
45 1
            $host = $connection['host'];
46 1
            $port = $connection['port'];
47 1
            $path = $connection['path'];
48 1
            $auth_key = $connection['auth_key'];
49 1
            $auth_secret = $connection['auth_secret'];
50 1
            $hostname = $connection['hostname'];
51 1
            $ignoreSsl = $connection['ssl_ignore'];
52
53 1
            if ($path[0] !== '/') {
54
                $path = '/' . $path;
55
            }
56
57 1
            $definition = clone $genericDefinition;
58 1
            $definition->setArguments([$protocol, $host, $port, $path, $auth_key, $auth_secret, $hostname, $ignoreSsl]);
59 1
            $container->setDefinition(sprintf('facile.crossbar.publisher.%s', $key), $definition);
60
        }
61 1
    }
62
63
    /**
64
     * @param ContainerBuilder $container
65
     * @return string The factory service name inside the container
66
     */
67 1
    private function addFactoryToContainer(ContainerBuilder $container)
68
    {
69 1
        $factoryDefinition = new Definition('Facile\CrossbarHTTPPublisherBundle\Publisher\Factory');
70 1
        $factoryDefinition->setPublic(false);
71 1
        $factoryName = 'facile.crossbar.publisher.factory';
72 1
        $container->setDefinition($factoryName, $factoryDefinition);
73
74 1
        return $factoryName;
75
    }
76
}
77