Passed
Push — master ( c0886a...23eada )
by Chris
03:14
created

EchoRequest::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace DaveRandom\LibLifxLan\Messages\Device\Requests;
4
5
use DaveRandom\LibLifxLan\Exceptions\InvalidValueException;
6
use DaveRandom\LibLifxLan\Messages\Message;
7
8
final class EchoRequest implements Message
9
{
10
    public const MESSAGE_TYPE_ID = 58;
11
    public const WIRE_SIZE = 64;
12
13
    private $payload;
14
15
    /**
16
     * @param string $payload
17
     * @throws InvalidValueException
18
     */
19 5
    public function __construct(string $payload)
20
    {
21 5
        if (\strlen($payload) !== 64) {
22 2
            throw new InvalidValueException("Echo request payload should be exactly 64 bytes");
23
        }
24
25 3
        $this->payload = $payload;
26
    }
27
28 1
    public function getPayload(): string
29
    {
30 1
        return $this->payload;
31
    }
32
33 1
    public function getTypeId(): int
34
    {
35 1
        return self::MESSAGE_TYPE_ID;
36
    }
37
38 1
    public function getWireSize(): int
39
    {
40 1
        return self::WIRE_SIZE;
41
    }
42
}
43