Passed
Branch master (74fab5)
by Kunal
03:19
created

RabbitMQMessage   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 109
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 17
c 1
b 0
f 1
dl 0
loc 109
rs 10
wmc 9

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getAmqpMessage() 0 3 2
A setConfig() 0 5 1
A setExchange() 0 5 1
A getStream() 0 3 1
A getExchange() 0 3 1
A getConfig() 0 3 1
A setStream() 0 5 1
A __construct() 0 5 1
1
<?php
2
3
namespace Kunnu\RabbitMQ;
4
5
use Illuminate\Support\Collection;
6
use PhpAmqpLib\Message\AMQPMessage;
7
8
class RabbitMQMessage
9
{
10
    /**
11
     * Message stream.
12
     *
13
     * @var string $stream
14
     */
15
    protected string $stream;
16
17
    /**
18
     * Message exchange.
19
     *
20
     * @var RabbitMQExchange|null $exchange
21
     */
22
    protected ?RabbitMQExchange $exchange = null;
23
24
    /**
25
     * Message config.
26
     *
27
     * @var Collection $config
28
     */
29
    protected Collection $config;
30
31
    /**
32
     * Create a new RabbitMQ Message instance.
33
     *
34
     * @param string $stream
35
     * @param array $config
36
     */
37
    public function __construct(string $stream, array $config = [])
38
    {
39
        $this
40
            ->setStream($stream)
41
            ->setConfig($config);
42
    }
43
44
    /**
45
     * Set message config.
46
     *
47
     * @param array $config
48
     *
49
     * @return RabbitMQMessage
50
     */
51
    public function setConfig(array $config): self
52
    {
53
        $this->config = new Collection($config);
54
55
        return $this;
56
    }
57
58
    /**
59
     * Get AMQP Message.
60
     *
61
     * @return AMQPMessage
62
     */
63
    public function getAmqpMessage(): AMQPMessage
64
    {
65
        return new AMQPMessage($this->stream, $this->config ? $this->config->toArray() : []);
66
    }
67
68
    /**
69
     * Set message stream.
70
     *
71
     * @param string $stream
72
     * @return self
73
     */
74
    public function setStream(string $stream): self
75
    {
76
        $this->stream = $stream;
77
78
        return $this;
79
    }
80
81
    /**
82
     * @return string
83
     */
84
    public function getStream(): string
85
    {
86
        return $this->stream;
87
    }
88
89
    /**
90
     * @return Collection
91
     */
92
    public function getConfig(): Collection
93
    {
94
        return $this->config;
95
    }
96
97
    /**
98
     * @return null|RabbitMQExchange
99
     */
100
    public function getExchange(): ?RabbitMQExchange
101
    {
102
        return $this->exchange;
103
    }
104
105
    /**
106
     * Set message exchange.
107
     *
108
     * @param RabbitMQExchange $exchange
109
     *
110
     * @return self
111
     */
112
    public function setExchange(RabbitMQExchange $exchange): self
113
    {
114
        $this->exchange = $exchange;
115
116
        return $this;
117
    }
118
}
119