Completed
Pull Request — master (#25)
by Michal
11:29
created

Message::getExecuteAt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

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
nc 1
nop 0
crap 1
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 string
27
     */
28
    private $created;
29
30
    /**
31
     * @var string
32
     */
33
    private $executeAt;
34
35
    /**
36
     * Native implementation of message.
37
     *
38 51
     * @var string   $type
39
     * @var array    $payload
40 51
     * @var string   $messageId
41 51
     * @var float    $created   timestamp (microtime(true))
42 51
     * @var float    $executeAt timestamp (microtime(true))
43 34
     */
44 51
    public function __construct(string $type, array $payload = null, string $messageId = null, float $created = null, float $executeAt = null)
45 51
    {
46 51
        $this->messageId = $messageId;
47 34
        if (!$messageId) {
48 51
            $this->messageId = Uuid::uuid4()->toString();
49 51
        }
50 51
        $this->created = $created;
0 ignored issues
show
Documentation Bug introduced by
The property $created was declared of type string, but $created 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...
51
        if (!$created) {
52
            $this->created = microtime(true);
0 ignored issues
show
Documentation Bug introduced by
The property $created was declared of type string, but microtime(true) 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...
53
        }
54
        $this->type = $type;
55 42
        $this->payload = $payload;
56
        $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...
57 42
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function getId(): string
63 39
    {
64
        return $this->messageId;
65 39
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    public function getCreated(): float
71 48
    {
72
        return $this->created;
73 48
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78
    public function getExecuteAt(): ?float
79 48
    {
80
        return $this->executeAt;
81 48
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86
    public function getType(): string
87
    {
88
        return $this->type;
89
    }
90
91
    /**
92
     * {@inheritdoc}
93
     */
94
    public function getPayload(): ?array
95
    {
96
        return $this->payload;
97
    }
98
}
99