Completed
Push — master ( 639ef0...066714 )
by Camilo
02:30
created

PubRel::createPayload()   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
final class PubRel extends ProtocolBase implements ReadableContentInterface, WritableContentInterface
16
{
17
    use ReadableContent, WritableContent;
18
19
    public $packetIdentifier = 0;
20
21
    const CONTROL_PACKET_VALUE = 6;
22
23
    public function fillObject(string $rawMQTTHeaders, ClientInterface $client): ReadableContentInterface
24
    {
25
        $this->packetIdentifier = $this->extractPacketIdentifier($rawMQTTHeaders);
26
        return $this;
27
    }
28
29
    /**
30
     * Creates the variable header that each method has
31
     * @return string
32
     * @throws \OutOfRangeException
33
     */
34
    public function createVariableHeader(): string
35
    {
36
        $this->specialFlags |= 2;
37
        return Utilities::convertNumberToBinaryString($this->packetIdentifier);
38
    }
39
40
    /**
41
     * Creates the actual payload to be sent
42
     * @return string
43
     */
44
    public function createPayload(): string
45
    {
46
        return '';
47
    }
48
49
    /**
50
     * PUBREL should ALWAYS expect an answer back (in the form of a PUBCOMP)
51
     * @return bool
52
     */
53
    public function shouldExpectAnswer(): bool
54
    {
55
        return true;
56
    }
57
58
    /**
59
     * @param ClientInterface $client
60
     * @param WritableContentInterface $originalRequest
61
     * @return bool
62
     * @throws \LogicException
63
     */
64
    public function performSpecialActions(ClientInterface $client, WritableContentInterface $originalRequest): bool
65
    {
66
        $this->logger->debug('Checking packet identifier on PubRel');
67
        /** @var PubRec $originalRequest */
68
        if ($this->packetIdentifier !== $originalRequest->packetIdentifier) {
69
            throw new \LogicException('Packet identifiers to not match!');
70
        }
71
        return false;
72
    }
73
}
74