Passed
Push — master ( fc052b...13a97b )
by Camilo
02:52
created

SubAck   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 33
ccs 0
cts 9
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A performSpecialActions() 0 12 2
A fillObject() 0 4 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\ProtocolBase;
9
use unreal4u\MQTT\Internals\ReadableContent;
10
use unreal4u\MQTT\Internals\ReadableContentInterface;
11
use unreal4u\MQTT\Internals\WritableContentInterface;
12
13
/**
14
 * Class SubAck
15
 * @package unreal4u\MQTT\Protocol
16
 */
17
final class SubAck extends ProtocolBase implements ReadableContentInterface
18
{
19
    use ReadableContent;
20
21
    const CONTROL_PACKET_VALUE = 9;
22
23
    /**
24
     * @var int
25
     */
26
    private $packetIdentifier = 0;
27
28
    public function fillObject(string $rawMQTTHeaders): ReadableContentInterface
29
    {
30
        $this->packetIdentifier = $this->extractPacketIdentifier($rawMQTTHeaders);
31
        return $this;
32
    }
33
34
    /**
35
     * @inheritdoc
36
     * @throws \LogicException
37
     */
38
    public function performSpecialActions(ClientInterface $client, WritableContentInterface $originalRequest): bool
39
    {
40
        /** @var Subscribe $originalRequest */
41
        if ($this->packetIdentifier !== $originalRequest->getPacketIdentifier()) {
42
            throw new \LogicException('Packet identifiers do not match!');
43
        }
44
45
        $client
46
            ->updateLastCommunication()
47
            ->setBlocking(false)
48
        ;
49
        return true;
50
    }
51
}
52