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

PowerTransition::setLevel()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 1
dl 8
loc 8
ccs 0
cts 7
cp 0
crap 12
rs 9.4285
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace DaveRandom\LibLifxLan\DataTypes\Light;
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 PowerTransition
10
{
11
    private $level;
12
    private $duration;
13
14
    /**
15
     * @param int $level
16
     * @throws InvalidValueException
17
     */
18 View Code Duplication
    private function setLevel(int $level): 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...
19
    {
20
        if ($level < 0 || $level > 65535) {
21
            throw new InvalidValueException("Power level {$level} outside allowable range of 0 - 65535");
22
        }
23
24
        $this->level = $level;
25
    }
26
27
    /**
28
     * @param int $duration
29
     * @throws InvalidValueException
30
     */
31 View Code Duplication
    private function setDuration(int $duration): 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...
32
    {
33
        if ($duration < UINT32_MIN || $duration > UINT32_MAX) {
34
            throw new InvalidValueException(
35
                "Transition duration {$duration} outside allowable range of " . UINT32_MIN . " - " . UINT32_MAX
36
            );
37
        }
38
39
        $this->duration = $duration;
40
    }
41
42
    /**
43
     * @param int $level
44
     * @param int $duration
45
     * @throws InvalidValueException
46
     */
47
    public function __construct(int $level, int $duration)
48
    {
49
        $this->setLevel($level);
50
        $this->setDuration($duration);
51
    }
52
53
    public function getLevel(): int
54
    {
55
        return $this->level;
56
    }
57
58
    public function getDuration(): int
59
    {
60
        return $this->duration;
61
    }
62
}
63