Completed
Push — master ( ba407f...6dbf2d )
by Chris
02:29
created

Firmware::setBuild()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace DaveRandom\LibLifxLan\DataTypes;
4
5
use DaveRandom\LibLifxLan\Exceptions\InvalidValueException;
6
use const DaveRandom\LibLifxLan\UINT32_MAX;
7
use const DaveRandom\LibLifxLan\UINT32_MIN;
8
use function DaveRandom\LibLifxLan\datetimeinterface_to_datetimeimmutable;
9
10
abstract class Firmware
11
{
12
    private $build;
13
    private $version;
14
15
    private function setBuild(\DateTimeImmutable $build): void
16
    {
17
        $this->build = $build;
18
    }
19
20
    /**
21
     * @param int $version
22
     * @throws InvalidValueException
23
     */
24 View Code Duplication
    private function setVersion(int $version): void
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
    {
26
        if ($version < UINT32_MIN || $version > UINT32_MAX) {
27
            throw new InvalidValueException(
28
                "Firmware version {$version} outside allowable range of " . UINT32_MIN . " - " . UINT32_MAX
29
            );
30
        }
31
32
        $this->version = $version;
33
    }
34
35
    /**
36
     * @param \DateTimeInterface $build
37
     * @param int $version
38
     * @throws InvalidValueException
39
     */
40
    protected function __construct(\DateTimeInterface $build, int $version)
41
    {
42
        $this->setBuild(datetimeinterface_to_datetimeimmutable($build));
43
        $this->setVersion($version);
44
    }
45
46
    public function getBuild(): \DateTimeImmutable
47
    {
48
        return $this->build;
49
    }
50
51
    public function getVersion(): int
52
    {
53
        return $this->version;
54
    }
55
}
56