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

FrameAddress::setAckRequired()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
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 DaveRandom\Network\MacAddress;
7
8
final class FrameAddress
9
{
10
    public const WIRE_SIZE = 16;
11
12
    private $target;
13
    private $ackRequired;
14
    private $responseRequired;
15
    private $sequenceNo;
16
17 9
    private function setTarget(MacAddress $target): void
18
    {
19 9
        $this->target = $target;
20
    }
21
22 9
    private function setAckRequired(bool $ackRequired): void
23
    {
24 9
        $this->ackRequired = $ackRequired;
25
    }
26
27 9
    private function setResponseRequired(bool $responseRequired): void
28
    {
29 9
        $this->responseRequired = $responseRequired;
30
    }
31
32
    /**
33
     * @param int $sequenceNo
34
     * @throws InvalidValueException
35
     */
36 9
    private function setSequenceNo(int $sequenceNo): void
37
    {
38 9
        if ($sequenceNo < 0 || $sequenceNo > 255) {
39 2
            throw new InvalidValueException("Sequence number value {$sequenceNo} outside allowable range 0 - 255");
40
        }
41
42 7
        $this->sequenceNo = $sequenceNo;
43
    }
44
45
    /**
46
     * @param MacAddress $target
47
     * @param bool $ackRequired
48
     * @param bool $responseRequired
49
     * @param int $sequenceNo
50
     * @throws InvalidValueException
51
     */
52 9
    public function __construct(MacAddress $target, bool $ackRequired, bool $responseRequired, int $sequenceNo)
53
    {
54 9
        $this->setTarget($target);
55 9
        $this->setAckRequired($ackRequired);
56 9
        $this->setResponseRequired($responseRequired);
57 9
        $this->setSequenceNo($sequenceNo);
58
    }
59
60 1
    public function getTarget(): MacAddress
61
    {
62 1
        return $this->target;
63
    }
64
65 1
    public function isAckRequired(): bool
66
    {
67 1
        return $this->ackRequired;
68
    }
69
70 1
    public function isResponseRequired(): bool
71
    {
72 1
        return $this->responseRequired;
73
    }
74
75 1
    public function getSequenceNo(): int
76
    {
77 1
        return $this->sequenceNo;
78
    }
79
}
80