Completed
Push — master ( 6dbf2d...486f74 )
by Chris
02:44
created

ProtocolHeader   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setType() 0 8 3
A __construct() 0 4 1
A getType() 0 4 1
1
<?php declare(strict_types=1);
2
3
namespace DaveRandom\LibLifxLan\Header;
4
5
use DaveRandom\LibLifxLan\Exceptions\InvalidValueException;
6
7
final class ProtocolHeader
8
{
9
    public const WIRE_SIZE = 12;
10
11
    private $type;
12
13
    /**
14
     * @param int $type
15
     * @throws InvalidValueException
16
     */
17 6
    private function setType(int $type): void
18
    {
19 6
        if ($type < 0 || $type > 65535) {
20 2
            throw new InvalidValueException("Message type {$type} outside allowable range of 0 - 65535");
21
        }
22
23 4
        $this->type = $type;
24
    }
25
26
    /**
27
     * @param int $type
28
     * @throws InvalidValueException
29
     */
30 6
    public function __construct(int $type)
31
    {
32 6
        $this->setType($type);
33
    }
34
35 1
    public function getType(): int
36
    {
37 1
        return $this->type;
38
    }
39
}
40