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

State::setPower()   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\DataTypes\Label;
6
use DaveRandom\LibLifxLan\Exceptions\InvalidValueException;
7
8
final class State
9
{
10
    private $color;
11
    private $power;
12
    private $label;
13
14
    private function setColor(HsbkColor $color): void
15
    {
16
        $this->color = $color;
17
    }
18
19
    /**
20
     * @param int $power
21
     * @throws InvalidValueException
22
     */
23 View Code Duplication
    private function setPower(int $power): 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...
24
    {
25
        if ($power < 0 || $power > 65535) {
26
            throw new InvalidValueException("Power level {$power} outside allowable range of 0 - 65535");
27
        }
28
29
        $this->power = $power;
30
    }
31
32
    private function setLabel(Label $label): void
33
    {
34
        $this->label = $label;
35
    }
36
37
    /**
38
     * @param HsbkColor $color
39
     * @param int $power
40
     * @param Label $label
41
     * @throws InvalidValueException
42
     */
43
    public function __construct(HsbkColor $color, int $power, Label $label)
44
    {
45
        $this->setColor($color);
46
        $this->setPower($power);
47
        $this->setLabel($label);
48
    }
49
50
    public function getColor(): HsbkColor
51
    {
52
        return $this->color;
53
    }
54
55
    public function getPower(): int
56
    {
57
        return $this->power;
58
    }
59
60
    public function getLabel(): Label
61
    {
62
        return $this->label;
63
    }
64
}
65