Completed
Push — master ( 0d7a8a...2e892a )
by Chris
03:11
created

Service::setTypeId()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 3
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 3
rs 9.4285
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A Service::__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 11
    public function __construct(int $typeId, int $port)
20
    {
21 11
        $this->typeId = validate_uint8('Service type ID', $typeId);
22 9
        $this->port = validate_uint32('Port', $port);
23
    }
24
25 1
    public function getTypeId(): int
26
    {
27 1
        return $this->typeId;
28
    }
29
30 1
    public function getPort(): int
31
    {
32 1
        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