Completed
Push — master ( 7a6b49...336156 )
by Camilo
02:22
created

PubAck::createPayload()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 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\WritableContent;
13
use unreal4u\MQTT\Internals\WritableContentInterface;
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, PacketIdentifierFunctionality;
21
22
    const CONTROL_PACKET_VALUE = 4;
23
24
    /**
25
     * @param string $rawMQTTHeaders
26
     * @param ClientInterface $client
27
     * @return ReadableContentInterface
28
     * @throws \OutOfRangeException
29
     */
30 3
    public function fillObject(string $rawMQTTHeaders, ClientInterface $client): ReadableContentInterface
31
    {
32 3
        $this->setPacketIdentifierFromRawHeaders($rawMQTTHeaders);
33 3
        return $this;
34
    }
35
36
    /**
37
     * @inheritdoc
38
     * @throws \LogicException
39
     */
40 2
    public function performSpecialActions(ClientInterface $client, WritableContentInterface $originalRequest): bool
41
    {
42
        /** @var Publish $originalRequest */
43 2
        if ($this->getPacketIdentifier() !== $originalRequest->getPacketIdentifier()) {
44 1
            throw new \LogicException('Packet identifiers to not match!');
45
        }
46 1
        return true;
47
    }
48
49
    /**
50
     * @return string
51
     * @throws \OutOfRangeException
52
     */
53 1
    public function createVariableHeader(): string
54
    {
55 1
        return $this->getPacketIdentifierBinaryRepresentation();
56
    }
57
58
    /**
59
     * Creates the actual payload to be sent
60
     * @return string
61
     */
62 1
    public function createPayload(): string
63
    {
64 1
        return '';
65
    }
66
67
    /**
68
     * @inheritdoc
69
     */
70 1
    public function expectAnswer(string $data, ClientInterface $client): ReadableContentInterface
71
    {
72 1
        return $this;
73
    }
74
75
    /**
76
     * Some responses won't expect an answer back, others do in some situations
77
     * @return bool
78
     */
79 1
    public function shouldExpectAnswer(): bool
80
    {
81 1
        return false;
82
    }
83
84
    /**
85
     * @inheritdoc
86
     */
87 1
    public function getOriginControlPacket(): int
88
    {
89 1
        return Publish::getControlPacketValue();
90
    }
91
}
92