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

BrokerPort   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

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