Completed
Push — master ( b2dfe1...1412d2 )
by Sam
02:32
created

AbstractMessage::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace Jalle19\StatusManager\Message;
4
5
/**
6
 * Base class for messages that can be sent between the server and the clients
7
 *
8
 * @package   Jalle19\StatusManager
9
 * @copyright Copyright &copy; Sam Stenvall 2016-
10
 * @license   https://www.gnu.org/licenses/gpl.html The GNU General Public License v2.0
11
 */
12
abstract class AbstractMessage implements \JsonSerializable
13
{
14
15
	const TYPE_STATUS_UPDATES              = 'statusUpdates';
16
	const TYPE_STATISTICS_POPULAR_CHANNELS = 'statisticsPopularChannels';
17
18
	/**
19
	 * @var string
20
	 */
21
	private $_type;
22
23
	/**
24
	 * @var mixed
25
	 */
26
	private $_payload;
27
28
29
	/**
30
	 * @param string $type
31
	 * @param mixed  $payload
32
	 */
33
	public function __construct($type, $payload)
34
	{
35
		$this->_type    = $type;
36
		$this->_payload = $payload;
37
	}
38
39
40
	/**
41
	 * @return string
42
	 */
43
	public function getType()
44
	{
45
		return $this->_type;
46
	}
47
48
49
	/**
50
	 * @return mixed
51
	 */
52
	public function getPayload()
53
	{
54
		return $this->_payload;
55
	}
56
57
58
	/**
59
	 * @inheritdoc
60
	 */
61
	public function jsonSerialize()
62
	{
63
		return [
64
			'type'    => $this->_type,
65
			'payload' => $this->_payload,
66
		];
67
	}
68
69
}
70