Completed
Push — master ( bb30b8...368962 )
by Camilo
02:11
created

UnsubAck   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 35
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fillObject() 0 9 2
A performSpecialActions() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace unreal4u\MQTT\Protocol;
6
7
use unreal4u\MQTT\Exceptions\UnmatchingPacketIdentifiers;
8
use unreal4u\MQTT\Internals\ClientInterface;
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
 * Class SubAck
16
 * @package unreal4u\MQTT\Protocol
17
 */
18
final class UnsubAck extends ProtocolBase implements ReadableContentInterface
19
{
20
    use ReadableContent;
21
22
    const CONTROL_PACKET_VALUE = 11;
23
24
    /**
25
     * @var int
26
     */
27
    private $packetIdentifier = 0;
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->readSocketData(3);
34
        }
35
36
        $this->packetIdentifier = $this->extractPacketIdentifier($rawMQTTHeaders);
37
        return $this;
38
    }
39
40
    /**
41
     * @inheritdoc
42
     * @throws \LogicException
43
     */
44
    public function performSpecialActions(ClientInterface $client, WritableContentInterface $originalRequest): bool
45
    {
46
        /** @var Unsubscribe $originalRequest */
47
        if ($this->packetIdentifier !== $originalRequest->getPacketIdentifier()) {
48
            throw new UnmatchingPacketIdentifiers('Packet identifiers do not match!');
49
        }
50
51
        $client->updateLastCommunication();
52
        return true;
53
    }
54
}
55