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

Effect::setTransient()   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\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 Effect
10
{
11
    public const SET_HUE        = 0b0001;
12
    public const SET_SATURATION = 0b0010;
13
    public const SET_BRIGHTNESS = 0b0100;
14
    public const SET_TEMPERATURE     = 0b1000;
15
    public const SET_ALL = self::SET_HUE | self::SET_SATURATION | self::SET_BRIGHTNESS | self::SET_TEMPERATURE;
16
17
    private $transient;
18
    private $color;
19
    private $period;
20
    private $cycles;
21
    private $skewRatio;
22
    private $waveform;
23
    private $options;
24
25
    private function setTransient(bool $transient): void
26
    {
27
        $this->transient = $transient;
28
    }
29
30
    private function setColor(HsbkColor $color): void
31
    {
32
        $this->color = $color;
33
    }
34
35
    /**
36
     * @param int $period
37
     * @throws InvalidValueException
38
     */
39
    private function setPeriod(int $period): void
40
    {
41
        if ($period < UINT32_MIN || $period > UINT32_MAX) {
42
            throw new InvalidValueException(
43
                "Period {$period} outside allowable range of " . UINT32_MIN . " - " . UINT32_MAX
44
            );
45
        }
46
47
        $this->period = $period;
48
    }
49
50
    private function setCycles(float $cycles): void
51
    {
52
        $this->cycles = $cycles;
53
    }
54
55
    /**
56
     * @param int $skewRatio
57
     * @throws InvalidValueException
58
     */
59
    private function setSkewRatio(int $skewRatio): void
60
    {
61
        if ($skewRatio < -32768 || $skewRatio > 32767) {
62
            throw new InvalidValueException("Skew ratio {$skewRatio} outside allowable range of -32768 - 32767");
63
        }
64
65
        $this->skewRatio = $skewRatio;
66
    }
67
68
    /**
69
     * @param int $waveform
70
     * @throws InvalidValueException
71
     */
72
    private function setWaveform(int $waveform): void
73
    {
74
        if ($waveform < 0 || $waveform > 255) {
75
            throw new InvalidValueException("Waveform {$waveform} outside allowable range of 0 - 255");
76
        }
77
78
        $this->waveform = $waveform;
79
    }
80
81
    private function setOptions(int $options): void
82
    {
83
        $this->options = $options;
84
    }
85
86
    /**
87
     * @param bool $transient
88
     * @param HsbkColor $color
89
     * @param int $period
90
     * @param float $cycles
91
     * @param int $skewRatio
92
     * @param int $waveform
93
     * @param int $options
94
     * @throws InvalidValueException
95
     */
96
    public function __construct(bool $transient, HsbkColor $color, int $period, float $cycles, int $skewRatio, int $waveform, int $options = self::SET_ALL)
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 155 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
97
    {
98
        $this->setTransient($transient);
99
        $this->setColor($color);
100
        $this->setPeriod($period);
101
        $this->setCycles($cycles);
102
        $this->setSkewRatio($skewRatio);
103
        $this->setWaveform($waveform);
104
        $this->setOptions($options);
105
    }
106
107
    public function isTransient(): bool
108
    {
109
        return $this->transient;
110
    }
111
112
    public function getColor(): HsbkColor
113
    {
114
        return $this->color;
115
    }
116
117
    public function getPeriod(): int
118
    {
119
        return $this->period;
120
    }
121
122
    public function getCycles(): float
123
    {
124
        return $this->cycles;
125
    }
126
127
    public function getSkewRatio(): int
128
    {
129
        return $this->skewRatio;
130
    }
131
132
    public function getWaveform(): int
133
    {
134
        return $this->waveform;
135
    }
136
137
    public function getOptions(): int
138
    {
139
        return $this->options;
140
    }
141
}
142