Passed
Push — master ( 0ad4bf...cebcdc )
by Camilo
02:13
created

UnsubAck   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 54.55%

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 40
ccs 6
cts 11
cp 0.5455
rs 10
c 0
b 0
f 0

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