Completed
Push — master ( 2ef37c...52cad6 )
by Oleg
02:13
created

AbstractMessage::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
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 15
    public function __construct(string $message)
31
    {
32 15
        $this->message = $message;
33 15
    }
34
35
    /**
36
     * @return string
37
     */
38 14
    public function getType(): string
39
    {
40 14
        return $this->type;
41
    }
42
43
    /**
44
     * @return string
45
     */
46 14
    public function getMessage(): string
47
    {
48 14
        return $this->message;
49
    }
50
51
    /**
52
     * @return string
53
     */
54 14
    public function getId(): string
55
    {
56 14
        if (!isset( $this->id)) {
57 14
            $this->id = uniqid();
58
        }
59 14
        return $this->id;
60
    }
61
62
    /**
63
     * @inheritdoc
64
     */
65 14
    public function jsonSerialize()
66
    {
67
        return [
68 14
            'id' => $this->getId(),
69 14
            'class' => $this->getType(),
70 14
            'message' => $this->getMessage(),
71
        ];
72
    }
73
}
74