Completed
Push — master ( 4b9f01...160a67 )
by Damian
02:21
created

Envelope   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

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