RabbitTrait::setQueue()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

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