Envelope   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 138
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 0
dl 0
loc 138
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A getCode() 0 4 1
A start() 0 6 1
A accept() 0 4 1
A next() 0 6 1
A isFinished() 0 4 1
A isSuccess() 0 4 1
A getResult() 0 4 1
A getErrorMessage() 0 4 1
A getDeferred() 0 4 1
A getPacket() 0 4 1
A isSilent() 0 4 1
1
<?php
2
/**
3
 * Envelope.php
4
 *
5
 * @copyright      More in license.md
6
 * @license        http://www.ipublikuj.eu
7
 * @author         Adam Kadlec http://www.ipublikuj.eu
8
 * @package        iPublikuj:MQTTClient!
9
 * @subpackage     React
10
 * @since          1.0.0
11
 *
12
 * @date           12.03.17
13
 */
14
15
declare(strict_types = 1);
16
17
namespace IPub\MQTTClient\Flow;
18
19
use React\Promise;
20
21
use BinSoul\Net\Mqtt;
22
23
/**
24
 * Decorates flows with data required for the Client class
25
 *
26
 * @package        iPublikuj:MQTTClient!
27
 * @subpackage     React
28
 *
29
 * @author         Adam Kadlec <[email protected]>
30
 */
31
final class Envelope implements Mqtt\Flow
32
{
33
	/**
34
	 * @var Mqtt\Flow
35
	 */
36
	private $flow;
37
38
	/**
39
	 * @var Promise\Deferred
40
	 */
41
	private $deferred;
42
43
	/**
44
	 * @var Mqtt\Packet
45
	 */
46
	private $packet;
47
48
	/**
49
	 * @var bool
50
	 */
51
	private $isSilent;
52
53
	/**
54
	 * @param Mqtt\Flow $flow
55
	 * @param Promise\Deferred $deferred
56
	 * @param Mqtt\Packet|NULL $packet
57
	 * @param bool $isSilent
58
	 */
59
	public function __construct(
60
		Mqtt\Flow $flow,
61
		Promise\Deferred $deferred,
62
		?Mqtt\Packet $packet = NULL,
63
		bool $isSilent = FALSE
64
	) {
65
		$this->flow = $flow;
66
		$this->deferred = $deferred;
67
		$this->packet = $packet;
68
		$this->isSilent = $isSilent;
69
	}
70
71
	/**
72
	 * {@inheritdoc}
73
	 */
74
	public function getCode()
75
	{
76
		return $this->flow->getCode();
77
	}
78
79
	/**
80
	 * {@inheritdoc}
81
	 */
82
	public function start()
83
	{
84
		$this->packet = $this->flow->start();
85
86
		return $this->packet;
87
	}
88
89
	/**
90
	 * {@inheritdoc}
91
	 */
92
	public function accept(Mqtt\Packet $packet)
93
	{
94
		return $this->flow->accept($packet);
95
	}
96
97
	/**
98
	 * {@inheritdoc}
99
	 */
100
	public function next(Mqtt\Packet $packet)
101
	{
102
		$this->packet = $this->flow->next($packet);
103
104
		return $this->packet;
105
	}
106
107
	/**
108
	 * {@inheritdoc}
109
	 */
110
	public function isFinished()
111
	{
112
		return $this->flow->isFinished();
113
	}
114
115
	/**
116
	 * {@inheritdoc}
117
	 */
118
	public function isSuccess()
119
	{
120
		return $this->flow->isSuccess();
121
	}
122
123
	/**
124
	 * {@inheritdoc}
125
	 */
126
	public function getResult()
127
	{
128
		return $this->flow->getResult();
129
	}
130
131
	/**
132
	 * {@inheritdoc}
133
	 */
134
	public function getErrorMessage()
135
	{
136
		return $this->flow->getErrorMessage();
137
	}
138
139
	/**
140
	 * Returns the associated deferred
141
	 *
142
	 * @return Promise\Deferred
143
	 */
144
	public function getDeferred() : Promise\Deferred
145
	{
146
		return $this->deferred;
147
	}
148
149
	/**
150
	 * Returns the current packet
151
	 *
152
	 * @return Mqtt\Packet
153
	 */
154
	public function getPacket() : Mqtt\Packet
155
	{
156
		return $this->packet;
157
	}
158
159
	/**
160
	 * Indicates if the flow should emit events
161
	 *
162
	 * @return bool
163
	 */
164
	public function isSilent() : bool
165
	{
166
		return $this->isSilent;
167
	}
168
}
169