UnsubAck   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 11
c 0
b 0
f 0
dl 0
loc 41
ccs 13
cts 13
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fillObject() 0 9 2
A performSpecialActions() 0 5 1
A getOriginControlPacket() 0 3 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\WritableContentInterface;
14
15
use function strlen;
16
17
/**
18
 * The UNSUBACK Packet is sent by the Server to the Client to confirm receipt of an UNSUBSCRIBE Packet.
19
 */
20
final class UnsubAck extends ProtocolBase implements ReadableContentInterface
21
{
22 1
    use ReadableContent;
23 1
    use PacketIdentifierFunctionality;
24
25
    private const CONTROL_PACKET_VALUE = 11;
26
27
    /**
28
     * @param string $rawMQTTHeaders
29
     * @param ClientInterface $client
30
     * @return ReadableContentInterface
31
     * @throws OutOfRangeException
32
     */
33 2
    public function fillObject(string $rawMQTTHeaders, ClientInterface $client): ReadableContentInterface
34
    {
35
        // Read the rest of the request out should only 1 byte have come in
36 2
        if (strlen($rawMQTTHeaders) === 1) {
37 1
            $rawMQTTHeaders .= $client->readBrokerData(3);
38
        }
39
40 2
        $this->setPacketIdentifierFromRawHeaders($rawMQTTHeaders);
41 2
        return $this;
42
    }
43
44
    /**
45
     * @inheritdoc
46
     * @throws \LogicException
47
     */
48 1
    public function performSpecialActions(ClientInterface $client, WritableContentInterface $originalRequest): bool
49
    {
50 1
        $this->controlPacketIdentifiers($originalRequest);
51 1
        $client->updateLastCommunication();
52 1
        return true;
53
    }
54
55
    /**
56
     * @inheritdoc
57
     */
58 1
    public function getOriginControlPacket(): int
59
    {
60 1
        return Unsubscribe::getControlPacketValue();
61
    }
62
}
63