QueuedMessage::getThrowable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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