QoSLevel   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
eloc 9
c 2
b 0
f 0
dl 0
loc 45
ccs 10
cts 10
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 3 1
A getQoSLevel() 0 3 1
A __construct() 0 10 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;
24
25
    /**
26
     * QoSLevel constructor.
27
     *
28
     * @param int $qosLevel
29
     *
30
     * @throws \unreal4u\MQTT\Exceptions\InvalidQoSLevel
31
     */
32 54
    public function __construct(int $qosLevel = 0)
33
    {
34 54
        if ($qosLevel > 2 || $qosLevel < 0) {
35 1
            throw new InvalidQoSLevel(sprintf(
36 1
                'The provided QoS level is invalid. Valid values are 0, 1 and 2 (Provided: %d)',
37
                $qosLevel
38
            ));
39
        }
40
41 53
        $this->qosLevel = $qosLevel;
42 53
    }
43
44
    /**
45
     * Gets the current QoS level
46
     *
47
     * @return int
48
     */
49 40
    public function getQoSLevel(): int
50
    {
51 40
        return $this->qosLevel;
52
    }
53
54 3
    public function __toString(): string
55
    {
56 3
        return (string)$this->qosLevel;
57
    }
58
}
59