Completed
Push — master ( bb7259...dc298a )
by Sam
03:00
created

AbstractMessage   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 50%

Importance

Changes 5
Bugs 0 Features 4
Metric Value
wmc 4
c 5
b 0
f 4
lcom 1
cbo 0
dl 0
loc 67
ccs 6
cts 12
cp 0.5
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getPayload() 0 4 1
A jsonSerialize() 0 7 1
A getType() 0 4 1
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_AUTHENTICATION_REQUEST        = 'authenticationRequest';
16
	const TYPE_AUTHENTICATION_RESPONSE       = 'authenticationResponse';
17
	const TYPE_STATUS_UPDATES                = 'statusUpdates';
18
	const TYPE_POPULAR_CHANNELS_REQUEST      = 'popularChannelsRequest';
19
	const TYPE_POPULAR_CHANNELS_RESPONSE     = 'popularChannelsResponse';
20
	const TYPE_MOST_ACTIVE_WATCHERS_REQUEST  = 'mostActiveWatchersRequest';
21
	const TYPE_MOST_ACTIVE_WATCHERS_RESPONSE = 'mostActiveWatchersResponse';
22
	const TYPE_INSTANCES_REQUEST             = 'instancesRequest';
23
	const TYPE_INSTANCES_RESPONSE            = 'instancesResponse';
24
	const TYPE_USERS_REQUEST                 = 'usersRequest';
25
	const TYPE_USERS_RESPONSE                = 'usersResponse';
26
27
	/**
28
	 * @var string
29
	 */
30
	private $_type;
31
32
	/**
33
	 * @var mixed
34
	 */
35
	private $_payload;
36
37
38
	/**
39
	 * @param string $type
40
	 * @param mixed  $payload
41
	 */
42 3
	public function __construct($type, $payload)
43
	{
44 3
		$this->_type    = $type;
45 3
		$this->_payload = $payload;
46 3
	}
47
48
49
	/**
50
	 * @return string
51
	 */
52 2
	public function getType()
53
	{
54 2
		return $this->_type;
55
	}
56
57
58
	/**
59
	 * @return mixed
60
	 */
61
	public function getPayload()
62
	{
63
		return $this->_payload;
64
	}
65
66
67
	/**
68
	 * @inheritdoc
69
	 */
70
	public function jsonSerialize()
71
	{
72
		return [
73
			'type'    => $this->_type,
74
			'payload' => $this->_payload,
75
		];
76
	}
77
78
}
79