AbstractMessage::getId()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DataFlowServer\Notification;
5
6
abstract class AbstractMessage implements MessageInterface
7
{
8
    /**
9
     * Type of the message
10
     *
11
     * @var string
12
     */
13
    protected $type;
14
    /**
15
     * Message
16
     *
17
     * @var string
18
     */
19
    protected $message;
20
    /**
21
     * Message identifier (unique id)
22
     *
23
     * @var string
24
     */
25
    protected $id;
26
27
    /**
28
     * @inheritdoc
29
     */
30 154
    public function __construct(string $message)
31
    {
32 154
        $this->message = $message;
33 154
    }
34
35
    /**
36
     * @return string
37
     */
38 154
    public function getType(): string
39
    {
40 154
        return $this->type;
41
    }
42
43
    /**
44
     * @return string
45
     */
46 154
    public function getMessage(): string
47
    {
48 154
        return $this->message;
49
    }
50
51
    /**
52
     * @return string
53
     */
54 154
    public function getId(): string
55
    {
56 154
        if (!isset($this->id)) {
57 154
            $this->id = uniqid();
58
        }
59 154
        return $this->id;
60
    }
61
62
    /**
63
     * @inheritdoc
64
     */
65 154
    public function jsonSerialize()
66
    {
67
        return [
68 154
            'id' => $this->getId(),
69 154
            'class' => $this->getType(),
70 154
            'message' => $this->getMessage(),
71
        ];
72
    }
73
}
74