Completed
Push — master ( accf18...c40548 )
by Camilo
02:13
created

PubAck::getOriginControlPacket()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
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\ProtocolBase;
9
use unreal4u\MQTT\Internals\ReadableContent;
10
use unreal4u\MQTT\Internals\ReadableContentInterface;
11
use unreal4u\MQTT\Internals\WritableContent;
12
use unreal4u\MQTT\Internals\WritableContentInterface;
13
use unreal4u\MQTT\Utilities;
14
15
/**
16
 * A PUBACK Packet is the response to a PUBLISH Packet with QoS level 1.
17
 */
18
final class PubAck extends ProtocolBase implements ReadableContentInterface, WritableContentInterface
19
{
20
    use ReadableContent, WritableContent;
21
22
    public $packetIdentifier = 0;
23
24
    const CONTROL_PACKET_VALUE = 4;
25
26 1
    public function fillObject(string $rawMQTTHeaders, ClientInterface $client): ReadableContentInterface
27
    {
28 1
        $this->packetIdentifier = $this->extractPacketIdentifier($rawMQTTHeaders);
29 1
        return $this;
30
    }
31
32
    /**
33
     * @inheritdoc
34
     * @throws \LogicException
35
     */
36
    public function performSpecialActions(ClientInterface $client, WritableContentInterface $originalRequest): bool
37
    {
38
        /** @var Publish $originalRequest */
39
        if ($this->packetIdentifier !== $originalRequest->packetIdentifier) {
0 ignored issues
show
introduced by
The condition $this->packetIdentifier ...quest->packetIdentifier can never be false.
Loading history...
Bug introduced by
The property packetIdentifier is declared private in unreal4u\MQTT\Protocol\Publish and cannot be accessed from this context.
Loading history...
40
            throw new \LogicException('Packet identifiers to not match!');
41
        }
42
        return true;
43
    }
44
45
    public function createVariableHeader(): string
46
    {
47
        return Utilities::convertNumberToBinaryString($this->packetIdentifier);
48
    }
49
50
    /**
51
     * Creates the actual payload to be sent
52
     * @return string
53
     */
54
    public function createPayload(): string
55
    {
56
        return '';
57
    }
58
59
    /**
60
     * @inheritdoc
61
     */
62
    public function expectAnswer(string $data, ClientInterface $client): ReadableContentInterface
63
    {
64
        return $this;
65
    }
66
67
    /**
68
     * Some responses won't expect an answer back, others do in some situations
69
     * @return bool
70
     */
71
    public function shouldExpectAnswer(): bool
72
    {
73
        return false;
74
    }
75
76
    /**
77
     * @inheritdoc
78
     */
79
    public function getOriginControlPacket(): int
80
    {
81
        return Publish::getControlPacketValue();
82
    }
83
}
84