Completed
Push — master ( 129581...a310fa )
by Damian
03:27
created

Envelope   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 46
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 3
A getTitle() 0 3 1
A getPayload() 0 3 1
A getTimestamp() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace Initx\Querabilis;
4
5
use DateTime;
6
7
final class Envelope
8
{
9
    /**
10
     * @var string
11
     */
12
    private $title;
13
14
    /**
15
     * @var string
16
     */
17
    private $payload;
18
19
    /**
20
     * @var DateTime
21
     */
22
    private $timestamp;
23
24 18
    public function __construct(string $payload, ?string $title = null, ?DateTime $timestamp = null)
25
    {
26 18
        $this->payload = $payload;
27 18
        $this->title = $title ?: \bin2hex(\random_bytes(7));
28 18
        $this->timestamp = $timestamp ?: new DateTime();
29 18
    }
30
31
    /**
32
     * @return string
33
     */
34 2
    public function getTitle(): string
35
    {
36 2
        return $this->title;
37
    }
38
39
    /**
40
     * @return string
41
     */
42 2
    public function getPayload(): string
43
    {
44 2
        return $this->payload;
45
    }
46
47
    /**
48
     * @return DateTime
49
     */
50 2
    public function getTimestamp(): DateTime
51
    {
52 2
        return $this->timestamp;
53
    }
54
}
55