Service   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 32
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getTypeId() 0 3 1
A getName() 0 6 2
A getPort() 0 3 1
A __construct() 0 4 1
1
<?php declare(strict_types=1);
2
3
namespace DaveRandom\LibLifxLan\DataTypes;
4
5
use DaveRandom\LibLifxLan\Exceptions\InvalidValueException;
6
use function DaveRandom\LibLifxLan\validate_uint32;
7
use function DaveRandom\LibLifxLan\validate_uint8;
8
9
final class Service
10
{
11
    private $typeId;
12
    private $port;
13
14
    /**
15
     * @param int $typeId
16
     * @param int $port
17
     * @throws InvalidValueException
18
     */
19 13
    public function __construct(int $typeId, int $port)
20
    {
21 13
        $this->typeId = validate_uint8('Service type ID', $typeId);
22 11
        $this->port = validate_uint32('Port', $port);
23
    }
24
25 3
    public function getTypeId(): int
26
    {
27 3
        return $this->typeId;
28
    }
29
30 3
    public function getPort(): int
31
    {
32 3
        return $this->port;
33
    }
34
35 2
    public function getName(): string
36
    {
37
        try {
38 2
            return ServiceTypes::parseValue($this->typeId);
39 1
        } catch (\InvalidArgumentException $e) {
40 1
            return "Unknown({$this->typeId})";
41
        }
42
    }
43
}
44