Test Setup Failed
Pull Request — master (#28)
by Patrick
02:56
created

AmqpClientFactory::getSerializerFacade()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
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