Passed
Push — master ( 055b76...bacc0b )
by Patrick
01:33 queued 12s
created

AmqpClientFactory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 22
c 1
b 0
f 1
dl 0
loc 49
ccs 0
cts 26
cp 0
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getQueuePluginCollection() 0 3 1
A getSerializerFacade() 0 3 1
A createConsumer() 0 7 1
A createAmqpContext() 0 12 1
A createProducer() 0 7 1
A getLogFacade() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of forecast.it.fill project.
7
 * (c) Patrick Jaja <[email protected]>
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace ForecastAutomation\AmqpClient;
13
14
use Enqueue\AmqpExt\AmqpConnectionFactory;
15
use Enqueue\AmqpExt\AmqpContext;
16
use ForecastAutomation\AmqpClient\Business\Consumer;
17
use ForecastAutomation\AmqpClient\Business\Producer;
18
use ForecastAutomation\Kernel\AbstractFactory;
19
use ForecastAutomation\Log\LogFacade;
20
use ForecastAutomation\QueueClient\Shared\Plugin\QueuePluginCollection;
21
use ForecastAutomation\Serializer\SerializerFacade;
22
23
class AmqpClientFactory extends AbstractFactory
24
{
25
    public function createConsumer(): Consumer
26
    {
27
        return new Consumer(
28
            $this->createAmqpContext(),
29
            $this->getQueuePluginCollection(),
30
            $this->getSerializerFacade(),
31
            $this->getLogFacade(),
32
        );
33
    }
34
35
    public function createProducer(): Producer
36
    {
37
        return new Producer(
38
            $this->createAmqpContext(),
39
            $this->getQueuePluginCollection(),
40
            $this->getSerializerFacade(),
41
            $this->getLogFacade(),
42
        );
43
    }
44
45
    public function createAmqpContext(): AmqpContext
46
    {
47
        return (new AmqpConnectionFactory(
48
            [
49
                'host' => $_ENV['AMQP_HOST'],
50
                'port' => (int) $_ENV['AMQP_PORT'],
51
                'vhost' => $_ENV['AMQP_VHOST'],
52
                'user' => $_ENV['AMQP_USER'],
53
                'pass' => $_ENV['AMQP_PASS'],
54
                'persisted' => false,
55
            ]
56
        ))->createContext();
57
    }
58
59
    public function getSerializerFacade(): SerializerFacade
60
    {
61
        return $this->getProvidedDependency(AmqpClientDependencyProvider::SERIALIZER_FACADE);
62
    }
63
64
    public function getQueuePluginCollection(): QueuePluginCollection
65
    {
66
        return $this->getProvidedDependency(AmqpClientDependencyProvider::QUEUE_PLUGIN_COLLECTION);
67
    }
68
69
    public function getLogFacade(): LogFacade
70
    {
71
        return $this->getProvidedDependency(AmqpClientDependencyProvider::LOG_FACADE);
72
    }
73
}
74