RabbitTrait::setReply()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Source\Infra\Queue\RabbitMQ;
6
7
/**
8
 * The global trait to use in Rabbitmq classes
9
 */
10
trait RabbitTrait
11
{
12
    /** @var string $queue */
13
    private $queue;
14
15
    /** @var string $exchanger */
16
    private $exchanger;
17
18
    /** @var bool $reply */
19
    private $reply;
20
21
    /**
22
     * @param string $queue
23
     * @return self
24
     */
25
    protected function setQueue(string $queue): self
26
    {
27
        $queue = trim($queue);
28
29
        if (empty($queue)) {
30
            throw new \InvalidArgumentException("Fila inválida!");
31
        }
32
33
        if (!filter_var($queue)) {
34
            throw new \InvalidArgumentException("Fila inválida!");
35
        }
36
37
        $this->queue = $queue;
38
        return $this;
39
    }
40
41
    /**
42
     * @param string $queue
43
     * @return self
44
     */
45
    protected function setExchanger(string $exchanger): self
46
    {
47
        $exchanger = trim($exchanger);
48
49
        if (empty($exchanger)) {
50
            throw new \InvalidArgumentException("Exchanger '{$exchanger}' inválido!");
51
        }
52
53
        if (!filter_var($exchanger)) {
54
            throw new \InvalidArgumentException("Exchanger '{$exchanger}' inválido!");
55
        }
56
57
        $this->exchanger = $exchanger;
58
        return $this;
59
    }
60
61
    /**
62
     * @param string $queue
63
     * @return self
64
     */
65
    protected function setReply(bool $reply): self
66
    {
67
        $this->reply = ($reply === true) ?? false;
68
69
        return $this;
70
    }
71
72
    /**
73
     * @return null|string
74
     */
75
    public function getQueue(): ?string
76
    {
77
        return $this->queue;
78
    }
79
80
    /**
81
     * @return null|string
82
     */
83
    public function getExchanger(): ?string
84
    {
85
        return $this->exchanger;
86
    }
87
88
    /**
89
     * @return null|bool
90
     */
91
    public function getReply(): ?bool
92
    {
93
        return $this->reply;
94
    }
95
}
96