Completed
Push — master ( 513769...fc6b51 )
by Camilo
02:35
created

BrokerPort::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 2
nop 1
crap 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace unreal4u\MQTT\DataTypes;
6
7
use unreal4u\MQTT\Exceptions\InvalidBrokerPort;
8
9
/**
10
 * This Value Object will always contain a valid broker port.
11
 */
12
final class BrokerPort
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 $brokerPort;
24
25
    /**
26
     * BrokerPort constructor.
27
     *
28
     * @param int $brokerPort
29
     * @throws \unreal4u\MQTT\Exceptions\InvalidBrokerPort
30
     */
31 25
    public function __construct(int $brokerPort = 1883)
32
    {
33 25
        if ($brokerPort > 65535 || $brokerPort < 1) {
34 2
            throw new InvalidBrokerPort(sprintf(
35 2
                'The provided broker port is invalid. Valid values are between 1 and 65535 (Provided: %d)',
36 2
                $brokerPort
37
            ));
38
        }
39
40 23
        $this->brokerPort = $brokerPort;
41 23
    }
42
43
    /**
44
     * Gets the current broker port
45
     *
46
     * @return int
47
     */
48 6
    public function getBrokerPort(): int
49
    {
50 6
        return $this->brokerPort;
51
    }
52
}
53