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

ProtocolVersion   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 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A getProtocolVersion() 0 3 1
A __toString() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace unreal4u\MQTT\DataTypes;
6
7
use unreal4u\MQTT\Exceptions\Connect\UnacceptableProtocolVersion;
8
9
/**
10
 * This Value Object will always contain a valid protocol version.
11
 */
12
final class ProtocolVersion
13
{
14
    /**
15
     * Holds the current protocol version
16
     *
17
     * @var string
18
     */
19
    private $protocolVersion;
20
21
    /**
22
     * QoSLevel constructor.
23
     *
24
     * @param string $protocolVersion
25
     * @throws \unreal4u\MQTT\Exceptions\Connect\UnacceptableProtocolVersion
26
     */
27 5
    public function __construct(string $protocolVersion = '3.1.1')
28
    {
29 5
        if ($protocolVersion !== '3.1.1') {
30 1
            throw new UnacceptableProtocolVersion('The specified protocol is invalid');
31
        }
32 4
        $this->protocolVersion = $protocolVersion;
33 4
    }
34
35
    /**
36
     * Gets the current protocol version
37
     *
38
     * @return string
39
     */
40 4
    public function getProtocolVersion(): string
41
    {
42 4
        return $this->protocolVersion;
43
    }
44
45 1
    public function __toString(): string
46
    {
47 1
        return $this->getProtocolVersion();
48
    }
49
}
50