Passed
Push — master ( d71bca...578a67 )
by Camilo
02:06
created

PubAck::createPayload()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace unreal4u\MQTT\Protocol;
6
7
use OutOfRangeException;
8
use unreal4u\MQTT\Internals\ClientInterface;
9
use unreal4u\MQTT\Internals\PacketIdentifierFunctionality;
10
use unreal4u\MQTT\Internals\ProtocolBase;
11
use unreal4u\MQTT\Internals\ReadableContent;
12
use unreal4u\MQTT\Internals\ReadableContentInterface;
13
use unreal4u\MQTT\Internals\WritableContent;
14
use unreal4u\MQTT\Internals\WritableContentInterface;
15
16
/**
17
 * A PUBACK Packet is the response to a PUBLISH Packet with QoS level 1.
18
 *
19
 * QoS lvl1:
20
 *   First packet: PUBLISH
21
 *   Second packet: PUBACK
22
 *
23
 * @see https://go.gliffy.com/go/publish/12498076
24
 */
25
final class PubAck extends ProtocolBase implements ReadableContentInterface, WritableContentInterface
26
{
27
    use ReadableContent;
28
    use /** @noinspection TraitsPropertiesConflictsInspection */
29
        WritableContent;
30
    use PacketIdentifierFunctionality;
31
32
    private const CONTROL_PACKET_VALUE = 4;
33
34
    /**
35
     * @param string $rawMQTTHeaders
36
     * @param ClientInterface $client
37
     * @return ReadableContentInterface
38
     * @throws OutOfRangeException
39
     */
40 1
    public function fillObject(string $rawMQTTHeaders, ClientInterface $client): ReadableContentInterface
41
    {
42 1
        $this->setPacketIdentifierFromRawHeaders($rawMQTTHeaders);
43 1
        return $this;
44
    }
45
46
    /**
47
     * @return string
48
     * @throws OutOfRangeException
49
     */
50 1
    public function createVariableHeader(): string
51
    {
52 1
        return $this->getPacketIdentifierBinaryRepresentation();
53
    }
54
55
    /**
56
     * Creates the actual payload to be sent
57
     * @return string
58
     */
59 1
    public function createPayload(): string
60
    {
61 1
        return '';
62
    }
63
64
    /**
65
     * @inheritdoc
66
     */
67 1
    public function expectAnswer(string $brokerBitStream, ClientInterface $client): ReadableContentInterface
68
    {
69 1
        return $this;
70
    }
71
72
    /**
73
     * Some responses won't expect an answer back, others do in some situations
74
     * @return bool
75
     */
76 1
    public function shouldExpectAnswer(): bool
77
    {
78 1
        return false;
79
    }
80
81
    /**
82
     * @inheritdoc
83
     */
84
    public function getOriginControlPacket(): int
85
    {
86
        return Publish::getControlPacketValue();
87
    }
88
}
89