Completed
Push — master ( f55639...d36af8 )
by Camilo
02:28
created

UnsubAck::fillObject()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 2
crap 2
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 2
    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 2
        if (\strlen($rawMQTTHeaders) === 1) {
33 1
            $rawMQTTHeaders .= $client->readBrokerData(3);
34
        }
35
36 2
        $this->setPacketIdentifierFromRawHeaders($rawMQTTHeaders);
37 2
        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