Completed
Push — master ( df1767...093280 )
by Camilo
02:16
created

PubAck   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 59
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A fillObject() 0 4 1
A createPayload() 0 3 1
A getOriginControlPacket() 0 3 1
A shouldExpectAnswer() 0 3 1
A expectAnswer() 0 3 1
A createVariableHeader() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace unreal4u\MQTT\Protocol;
6
7
use unreal4u\MQTT\Internals\ClientInterface;
8
use unreal4u\MQTT\Internals\PacketIdentifierFunctionality;
9
use unreal4u\MQTT\Internals\ProtocolBase;
10
use unreal4u\MQTT\Internals\ReadableContent;
11
use unreal4u\MQTT\Internals\ReadableContentInterface;
12
use unreal4u\MQTT\Internals\WritableContent;
13
use unreal4u\MQTT\Internals\WritableContentInterface;
14
15
/**
16
 * A PUBACK Packet is the response to a PUBLISH Packet with QoS level 1.
17
 */
18
final class PubAck extends ProtocolBase implements ReadableContentInterface, WritableContentInterface
19
{
20
    use ReadableContent, WritableContent, PacketIdentifierFunctionality;
21
22
    const CONTROL_PACKET_VALUE = 4;
23
24
    /**
25
     * @param string $rawMQTTHeaders
26
     * @param ClientInterface $client
27
     * @return ReadableContentInterface
28
     * @throws \OutOfRangeException
29
     */
30 2
    public function fillObject(string $rawMQTTHeaders, ClientInterface $client): ReadableContentInterface
31
    {
32 2
        $this->setPacketIdentifierFromRawHeaders($rawMQTTHeaders);
33 2
        return $this;
34
    }
35
36
    /**
37
     * @return string
38
     * @throws \OutOfRangeException
39
     */
40 1
    public function createVariableHeader(): string
41
    {
42 1
        return $this->getPacketIdentifierBinaryRepresentation();
43
    }
44
45
    /**
46
     * Creates the actual payload to be sent
47
     * @return string
48
     */
49 1
    public function createPayload(): string
50
    {
51 1
        return '';
52
    }
53
54
    /**
55
     * @inheritdoc
56
     */
57 1
    public function expectAnswer(string $data, ClientInterface $client): ReadableContentInterface
58
    {
59 1
        return $this;
60
    }
61
62
    /**
63
     * Some responses won't expect an answer back, others do in some situations
64
     * @return bool
65
     */
66 1
    public function shouldExpectAnswer(): bool
67
    {
68 1
        return false;
69
    }
70
71
    /**
72
     * @inheritdoc
73
     */
74 1
    public function getOriginControlPacket(): int
75
    {
76 1
        return Publish::getControlPacketValue();
77
    }
78
}
79