Passed
Push — master ( f12820...2e6535 )
by Damian
02:05
created

Envelope   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 45.45%

Importance

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

4 Methods

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