Completed
Push — master ( e04e5a...e45d07 )
by Tomas
14:43
created

Message::getRetries()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

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
nc 1
nop 0
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Tomaj\Hermes;
5
6
use Ramsey\Uuid\Uuid;
7
8
class Message implements MessageInterface
9
{
10
    /**
11
     * @var string
12
     */
13
    private $type;
14
15
    /**
16
     * @var array
17
     */
18
    private $payload;
19
20
    /**
21
     * @var string
22
     */
23
    private $messageId;
24
25
    /**
26
     * @var float
27
     */
28
    private $created;
29
30
    /**
31
     * @var string
32
     */
33
    private $executeAt;
34
35
    /**
36
     * @var int
37
     */
38 51
    private $retries;
39
40 51
    /**
41 51
     * Native implementation of message.
42 51
     *
43 34
     * @var string   $type
44 51
     * @var array    $payload
45 51
     * @var string   $messageId
46 51
     * @var float    $created   timestamp (microtime(true))
47 34
     * @var float    $executeAt timestamp (microtime(true))
48 51
     * @var int      $retries
49 51
     */
50 51
    public function __construct(string $type, array $payload = null, string $messageId = null, float $created = null, float $executeAt = null, int $retries = 0)
51
    {
52
        $this->messageId = $messageId;
53
        if (!$messageId) {
54
            try {
55 42
                $this->messageId = Uuid::uuid4()->toString();
56
            } catch (\Exception $e) {
57 42
                $this->messageId = rand(10000, 99999999);
0 ignored issues
show
Documentation Bug introduced by
The property $messageId was declared of type string, but rand(10000, 99999999) is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
58
            }
59
60
        }
61
        $this->created = $created;
62
        if (!$created) {
63 39
            $this->created = microtime(true);
64
        }
65 39
        $this->type = $type;
66
        $this->payload = $payload;
67
        $this->executeAt = $executeAt;
0 ignored issues
show
Documentation Bug introduced by
The property $executeAt was declared of type string, but $executeAt is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
68
        $this->retries = $retries;
69
    }
70
71 48
    /**
72
     * {@inheritdoc}
73 48
     */
74
    public function getId(): string
75
    {
76
        return $this->messageId;
77
    }
78
79 48
    /**
80
     * {@inheritdoc}
81 48
     */
82
    public function getCreated(): float
83
    {
84
        return $this->created;
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90
    public function getExecuteAt(): ?float
91
    {
92
        return $this->executeAt;
93
    }
94
95
    /**
96
     * {@inheritdoc}
97
     */
98
    public function getType(): string
99
    {
100
        return $this->type;
101
    }
102
103
    /**
104
     * {@inheritdoc}
105
     */
106
    public function getPayload(): ?array
107
    {
108
        return $this->payload;
109
    }
110
111
    /**
112
     * {@inheritdoc}
113
     */
114
    public function getRetries(): int
115
    {
116
        return $this->retries;
117
    }
118
}
119