Completed
Push — master ( 057fec...4b209d )
by Cody
02:09
created

QueuedMessage::getDeliveryTag()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Ccovey\RabbitMQ;
4
5
use PhpAmqpLib\Channel\AMQPChannel;
6
use PhpAmqpLib\Message\AMQPMessage;
7
use Throwable;
8
9
class QueuedMessage implements QueuedMessageInterface
10
{
11
    /**
12
     * @var AMQPMessage
13
     */
14
    private $message;
15
16
    /**
17
     * @var array
18
     */
19
    private $body;
20
21
    /**
22
     * @var AMQPChannel
23
     */
24
    private $queueName;
25
26
    /**
27
     * @var bool
28
     */
29
    private $failed = false;
30
31
    /**
32
     * @var Throwable|null
33
     */
34
    private $throwable;
35
36 2
    public function __construct(AMQPMessage $message)
37
    {
38 2
        $this->message = $message;
39 2
        $this->body = json_decode($this->message->body, 1);
40 2
        $this->queueName = $this->message->delivery_info['routing_key'];
41 2
    }
42
43 1
    public function getQueueName() : string
44
    {
45 1
        return $this->queueName;
46
    }
47
48 1
    public function getDeliveryTag() : string
49
    {
50 1
        return $this->message->delivery_info['delivery_tag'];
51
    }
52
53
    public function fail(Throwable $throwable = null)
54
    {
55
        $this->throwable = $throwable;
56
        $this->failed = true;
57
    }
58
59
    public function isFailed() : bool
60
    {
61
        return $this->failed;
62
63
    }
64
65
    public function getThrowable()
66
    {
67
        return $this->throwable;
68
    }
69
70 2
    public function getBody() : array
71
    {
72 2
        return $this->body;
73
    }
74
75
    public function getRawBody() : string
76
    {
77
        return $this->message->body;
78
    }
79
80
    /**
81
     * @param string $value
82
     *
83
     * @return mixed|null
84
     */
85 1
    public function __get(string $value)
86
    {
87 1
        return $this->body[$value] ?? null;
88
    }
89
}
90