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

QoSLevel   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 36
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getQoSLevel() 0 3 1
A __construct() 0 6 3
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