Completed
Push — master ( 65967c...597be2 )
by Cody
02:06
created

QueuedMessage::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Ccovey\RabbitMQ;
4
5
use PhpAmqpLib\Channel\AMQPChannel;
6
use PhpAmqpLib\Message\AMQPMessage;
7
8
class QueuedMessage implements QueuedMessageInterface
9
{
10
    /**
11
     * @var AMQPMessage
12
     */
13
    private $message;
14
15
    /**
16
     * @var array
17
     */
18
    private $body;
19
20
    /**
21
     * @var AMQPChannel
22
     */
23
    private $queueName;
24
25 1
    public function __construct(AMQPMessage $message)
26
    {
27 1
        $this->message = $message;
28 1
        $this->body = json_decode($this->message->body, 1);
29 1
        $this->queueName = $this->message->delivery_info['routing_key'];
30 1
    }
31
32
    public function getQueueName() : string
33
    {
34
        return $this->queueName;
35
    }
36
37
    public function getBody() : array
38
    {
39
        return $this->body;
40
    }
41
42
    /**
43
     * @param string $value
44
     *
45
     * @return mixed|null
46
     */
47
    public function __get(string $value)
48
    {
49
        return $this->body[$value] ?? null;
50
    }
51
}
52