Completed
Push — master ( 115ddb...800837 )
by Camilo
02:15
created

QoSLevel::getQoSLevel()   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\DataTypes;
6
7
use unreal4u\MQTT\Exceptions\InvalidQoSLevel;
8
9
/**
10
 * This Value Object will always contain a valid QoS level.
11
 */
12
final class QoSLevel
13
{
14
    /**
15
     * This field indicates the level of assurance for delivery of an Application Message. Can be 0, 1 or 2
16
     *
17
     * 0: At most once delivery (default)
18
     * 1: At least once delivery
19
     * 2: Exactly once delivery
20
     *
21
     * @var int
22
     */
23
    private $qosLevel = 0;
24
25
    /**
26
     * QoSLevel constructor.
27
     * @param int $QoSLevel
28
     * @throws \unreal4u\MQTT\Exceptions\InvalidQoSLevel
29
     */
30 4
    public function __construct(int $QoSLevel = 0)
31
    {
32 4
        if ($QoSLevel > 2 || $QoSLevel < 0) {
33 1
            throw new InvalidQoSLevel(sprintf(
34 1
                'The provided QoS level is invalid. Valid values are 0, 1 and 2 (Provided: %d)',
35 1
                $QoSLevel
36
            ));
37
        }
38 3
    }
39
40
    /**
41
     * Gets the current QoS level
42
     *
43
     * @return int
44
     */
45 3
    public function getQoSLevel(): int
46
    {
47 3
        return $this->qosLevel;
48
    }
49
}
50