Completed
Push — master ( 336156...094757 )
by Camilo
02:28
created

PubComp::getOriginControlPacket()   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\Application\EmptyReadableResponse;
8
use unreal4u\MQTT\Internals\ClientInterface;
9
use unreal4u\MQTT\Internals\PacketIdentifierFunctionality;
10
use unreal4u\MQTT\Internals\ProtocolBase;
11
use unreal4u\MQTT\Internals\ReadableContent;
12
use unreal4u\MQTT\Internals\ReadableContentInterface;
13
use unreal4u\MQTT\Internals\WritableContent;
14
use unreal4u\MQTT\Internals\WritableContentInterface;
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, PacketIdentifierFunctionality;
24
25
    const CONTROL_PACKET_VALUE = 7;
26
27
    /**
28
     * @param string $rawMQTTHeaders
29
     * @param ClientInterface $client
30
     * @return ReadableContentInterface
31
     * @throws \OutOfRangeException
32
     */
33 2
    public function fillObject(string $rawMQTTHeaders, ClientInterface $client): ReadableContentInterface
34
    {
35 2
        $this->setPacketIdentifierFromRawHeaders($rawMQTTHeaders);
36 2
        return $this;
37
    }
38
39
    /**
40
     * @inheritdoc
41
     * @throws \LogicException
42
     */
43 2
    public function performSpecialActions(ClientInterface $client, WritableContentInterface $originalRequest): bool
44
    {
45 2
        return $this->controlPacketIdentifiers($originalRequest);
46
    }
47
48
    /**
49
     * Creates the variable header that each method has
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 new EmptyReadableResponse($this->logger);
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 PubRel::getControlPacketValue();
90
    }
91
}
92