Passed
Push — master ( 8634b9...ba407f )
by Chris
14:07
created

Frame::__construct()   D

Complexity

Conditions 9
Paths 5

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 9

Importance

Changes 0
Metric Value
cc 9
eloc 15
nc 5
nop 6
dl 0
loc 25
ccs 15
cts 15
cp 1
crap 9
rs 4.909
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
use const DaveRandom\LibLifxLan\UINT32_MAX;
7
use const DaveRandom\LibLifxLan\UINT32_MIN;
8
9
final class Frame
10
{
11
    public const WIRE_SIZE = 8;
12
13
    private $size;
14
    private $origin;
15
    private $tagged;
16
    private $addressable;
17
    private $protocolNo;
18
    private $source;
19
20
    /**
21
     * @param int $size
22
     * @param int $origin
23
     * @param bool $tagged
24
     * @param bool $addressable
25
     * @param int $protocolNo
26
     * @param int $source
27
     * @throws InvalidValueException
28
     */
29 29
    public function __construct(int $size, int $origin, bool $tagged, bool $addressable, int $protocolNo, int $source)
30
    {
31 29
        if ($size < 0 || $size > 65535) {
32 4
            throw new InvalidValueException("Message size {$size} outside allowable range of 0 - 65535");
33
        }
34
35 25
        if ($origin < 0 || $origin > 3) {
36 4
            throw new InvalidValueException("Message origin value {$origin} outside allowable range 0 - 3");
37
        }
38
39 21
        if ($protocolNo < 0 || $protocolNo > 4095) {
40 4
            throw new InvalidValueException("Message protocol number {$protocolNo} outside allowable range 0 - 4095");
41
        }
42
43 17
        if ($source < UINT32_MIN || $source > UINT32_MAX) {
44 2
            throw new InvalidValueException("Message source value {$source} outside allowable range " . UINT32_MIN . " - " . UINT32_MAX);
45
        }
46
47 15
        $this->size = $size;
48 15
        $this->origin = $origin;
49 15
        $this->tagged = $tagged;
50 15
        $this->addressable = $addressable;
51 15
        $this->protocolNo = $protocolNo;
52 15
        $this->source = $source;
53
    }
54
55 2
    public function getSize(): int
56
    {
57 2
        return $this->size;
58
    }
59
60 2
    public function getOrigin(): int
61
    {
62 2
        return $this->origin;
63
    }
64
65 2
    public function isTagged(): bool
66
    {
67 2
        return $this->tagged;
68
    }
69
70 2
    public function isAddressable(): bool
71
    {
72 2
        return $this->addressable;
73
    }
74
75 2
    public function getProtocolNo(): int
76
    {
77 2
        return $this->protocolNo;
78
    }
79
80 2
    public function getSource(): int
81
    {
82 2
        return $this->source;
83
    }
84
}
85