Completed
Push — master ( d873b8...8f1f59 )
by Cody
04:58
created

QueuedMessage   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 2
cbo 1
dl 0
loc 86
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getQueueName() 0 4 1
A getDeliveryTag() 0 4 1
A fail() 0 5 1
A isFailed() 0 5 1
A getThrowable() 0 4 1
A getBody() 0 4 1
A getRawBody() 0 4 1
A setStopWatchEvent() 0 4 1
A __get() 0 4 1
1
<?php
2
3
namespace Ccovey\RabbitMQ;
4
5
use PhpAmqpLib\Channel\AMQPChannel;
6
use PhpAmqpLib\Message\AMQPMessage;
7
use Symfony\Component\Stopwatch\StopwatchEvent;
8
use Throwable;
9
10
class QueuedMessage implements QueuedMessageInterface
11
{
12
    /**
13
     * @var AMQPMessage
14
     */
15
    private $message;
16
17
    /**
18
     * @var array
19
     */
20
    private $body;
21
22
    /**
23
     * @var AMQPChannel
24
     */
25
    private $queueName;
26
27
    /**
28
     * @var bool
29
     */
30
    private $failed = false;
31
32
    /**
33
     * @var Throwable|null
34
     */
35
    private $throwable;
36
37 2
    public function __construct(AMQPMessage $message)
38
    {
39 2
        $this->message = $message;
40 2
        $this->body = json_decode($this->message->body, 1);
41 2
        $this->queueName = $this->message->delivery_info['routing_key'];
42 2
    }
43
44 1
    public function getQueueName() : string
45
    {
46 1
        return $this->queueName;
47
    }
48
49 1
    public function getDeliveryTag() : string
50
    {
51 1
        return $this->message->delivery_info['delivery_tag'];
52
    }
53
54
    public function fail(Throwable $throwable = null)
55
    {
56
        $this->throwable = $throwable;
57
        $this->failed = true;
58
    }
59
60
    public function isFailed() : bool
61
    {
62
        return $this->failed;
63
64
    }
65
66
    public function getThrowable()
67
    {
68
        return $this->throwable;
69
    }
70
71 2
    public function getBody() : array
72
    {
73 2
        return $this->body;
74
    }
75
76
    public function getRawBody() : string
77
    {
78
        return $this->message->body;
79
    }
80
81
    public function setStopWatchEvent(StopwatchEvent $stopwatchEvent)
82
    {
83
        $this->stopwatchEvent = $stopwatchEvent;
0 ignored issues
show
Bug introduced by
The property stopwatchEvent does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
84
    }
85
86
    /**
87
     * @param string $value
88
     *
89
     * @return mixed|null
90
     */
91 1
    public function __get(string $value)
92
    {
93 1
        return $this->body[$value] ?? null;
94
    }
95
}
96