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

ProtocolHeader::setType()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 1
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 3
rs 9.4285
c 0
b 0
f 0
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