Test Failed
Push — master ( 9d3a5c...c5f273 )
by Sebastian
08:26
created

PercentChannel::getDecimal()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * @package Application Utils
4
 * @subpackage RGBAColor
5
 * @see \AppUtils\RGBAColor\ColorChannel\PercentChannel
6
 */
7
8
declare(strict_types=1);
9
10
namespace AppUtils\RGBAColor\ColorChannel;
11
12
use AppUtils\RGBAColor\ColorChannel;
13
use AppUtils\RGBAColor\UnitsConverter;
14
15
/**
16
 * Color channel with values from 0 to 100.
17
 *
18
 * Native value: {@see self::getPercent()} and
19
 * {@see self::getPercentRounded()}.
20
 *
21
 * @package Application Utils
22
 * @subpackage RGBAColor
23
 * @author Sebastian Mordziol <[email protected]>
24
 */
25
class PercentChannel extends ColorChannel
26
{
27
    public const VALUE_MIN = 0.0;
28
    public const VALUE_MAX = 100.0;
29
30
    /**
31
     * @var float
32
     */
33
    protected float $value;
34
35
    /**
36
     * @param int|float $value
37
     */
38
    public function __construct($value)
39
    {
40
        $value = (float)$value;
41
42
        if($value < self::VALUE_MIN) { $value = self::VALUE_MIN; }
43
        if($value > self::VALUE_MAX) { $value = self::VALUE_MAX; }
44
45
        $this->value = $value;
46
    }
47
48
    public function getValue() : float
49
    {
50
        return $this->value;
51
    }
52
53
    public function getAlpha() : float
54
    {
55
        return UnitsConverter::percent2Alpha($this->value);
56
    }
57
58
    public function get8Bit() : int
59
    {
60
        return UnitsConverter::percent2IntEightBit($this->value);
61
    }
62
63
    public function get7Bit() : int
64
    {
65
        return UnitsConverter::percent2IntSevenBit($this->value);
66
    }
67
68
    public function getPercent() : float
69
    {
70
        return $this->value;
71
    }
72
73
    public function invert() : PercentChannel
74
    {
75
        return ColorChannel::percent(100-$this->value);
76
    }
77
}
78