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

PubComp::shouldExpectAnswer()   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\Application\EmptyReadableResponse;
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\WritableContent;
13
use unreal4u\MQTT\Internals\WritableContentInterface;
14
use unreal4u\MQTT\Utilities;
15
16
/**
17
 * The PUBCOMP Packet is the response to a PUBREL Packet.
18
 *
19
 * It is the fourth and final packet of the QoS 2 protocol exchange.
20
 */
21
final class PubComp extends ProtocolBase implements ReadableContentInterface, WritableContentInterface
22
{
23
    use ReadableContent, WritableContent;
24
25
    public $packetIdentifier = 0;
26
27
    const CONTROL_PACKET_VALUE = 7;
28
29
    public function fillObject(string $rawMQTTHeaders, ClientInterface $client): ReadableContentInterface
30
    {
31
        $this->packetIdentifier = $this->extractPacketIdentifier($rawMQTTHeaders);
32
        return $this;
33
    }
34
35
    /**
36
     * Creates the variable header that each method has
37
     * @return string
38
     * @throws \OutOfRangeException
39
     */
40
    public function createVariableHeader(): string
41
    {
42
        return Utilities::convertNumberToBinaryString($this->packetIdentifier);
43
    }
44
45
    /**
46
     * Creates the actual payload to be sent
47
     * @return string
48
     */
49
    public function createPayload(): string
50
    {
51
        // TODO: Implement createPayload() method.
52
        return '';
53
    }
54
55
    /**
56
     * @inheritdoc
57
     */
58
    public function expectAnswer(string $data, ClientInterface $client): ReadableContentInterface
59
    {
60
        return new EmptyReadableResponse($this->logger);
61
    }
62
63
    /**
64
     * Some responses won't expect an answer back, others do in some situations
65
     * @return bool
66
     */
67
    public function shouldExpectAnswer(): bool
68
    {
69
        return false;
70
    }
71
72
    /**
73
     * @inheritdoc
74
     */
75
    public function getOriginControlPacket(): int
76
    {
77
        return PubRel::getControlPacketValue();
78
    }
79
}
80