Passed
Pull Request — 0.4 (#35)
by jean
03:56
created

MessageProviderFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 33
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A factory() 0 20 3
1
<?php
2
3
namespace Darkilliant\MqProcessBundle\Message\Provider;
4
5
use PhpAmqpLib\Connection\AMQPStreamConnection;
6
use Psr\Container\ContainerInterface;
7
8
class MessageProviderFactory
9
{
10
    /** @var array */
11
    private $messageProvider = [];
12
13
    /** @var ContainerInterface */
14
    private $container;
15
16 2
    public function __construct(ContainerInterface $container)
17
    {
18 2
        $this->container = $container;
19 2
    }
20
21 2
    public function factory(string $name, array $config)
22
    {
23 2
        if (isset($this->messageProvider[$name])) {
24 1
            return $this->messageProvider[$name];
25
        }
26
27 2
        if ('amqp_lib' === $config['client']) {
28
            /** @var $connexion AMQPStreamConnection */
29 1
            $connexion = $this->container->get($config['connexion'] ?? 'darkilliant_mqprocess_connection');
30
31 1
            return $this->messageProvider[$name] = new AmqpMessageProvider(
32 1
                $connexion->channel(),
33 1
                $config['queue'],
34 1
                $config['exchange'],
35 1
                $config['persistant'],
36 1
                $config['batch_count']
37
            );
38
        }
39
40 1
        return null;
41
    }
42
}
43