Issues (19)

src/RabbitMQMessage.php (1 issue)

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
14
     */
15
    protected string $stream;
16
17
    /**
18
     * Message exchange.
19
     *
20
     * @var RabbitMQExchange|null
21
     */
22
    protected ?RabbitMQExchange $exchange = null;
23
24
    /**
25
     * Message config.
26
     *
27
     * @var Collection
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
     * @return RabbitMQMessage
49
     */
50
    public function setConfig(array $config): self
51
    {
52
        $this->config = new Collection($config);
0 ignored issues
show
$config of type array is incompatible with the type Illuminate\Contracts\Support\Arrayable expected by parameter $items of Illuminate\Support\Collection::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

52
        $this->config = new Collection(/** @scrutinizer ignore-type */ $config);
Loading history...
53
54
        return $this;
55
    }
56
57
    /**
58
     * Get AMQP Message.
59
     *
60
     * @return AMQPMessage
61
     */
62
    public function getAmqpMessage(): AMQPMessage
63
    {
64
        return new AMQPMessage($this->stream, $this->config ? $this->config->toArray() : []);
65
    }
66
67
    /**
68
     * Set message stream.
69
     *
70
     * @param  string  $stream
71
     * @return self
72
     */
73
    public function setStream(string $stream): self
74
    {
75
        $this->stream = $stream;
76
77
        return $this;
78
    }
79
80
    /**
81
     * @return string
82
     */
83
    public function getStream(): string
84
    {
85
        return $this->stream;
86
    }
87
88
    /**
89
     * @return Collection
90
     */
91
    public function getConfig(): Collection
92
    {
93
        return $this->config;
94
    }
95
96
    /**
97
     * @return null|RabbitMQExchange
98
     */
99
    public function getExchange(): ?RabbitMQExchange
100
    {
101
        return $this->exchange;
102
    }
103
104
    /**
105
     * Set message exchange.
106
     *
107
     * @param  RabbitMQExchange  $exchange
108
     * @return self
109
     */
110
    public function setExchange(RabbitMQExchange $exchange): self
111
    {
112
        $this->exchange = $exchange;
113
114
        return $this;
115
    }
116
}
117