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

ProtocolVersion::getProtocolVersion()   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\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