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

EightBitChannel::getAlpha()   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\EightBitChannel
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 255.
17
 *
18
 * Native value: {@see self::get8Bit()} and
19
 * {@see self::getHexadecimal()}.
20
 *
21
 * @package Application Utils
22
 * @subpackage RGBAColor
23
 * @author Sebastian Mordziol <[email protected]>
24
 */
25
class EightBitChannel extends ColorChannel
26
{
27
    public const VALUE_MIN = 0;
28
    public const VALUE_MAX = 255;
29
30
    /**
31
     * @var int
32
     */
33
    private int $value;
34
35
    public function __construct(int $value)
36
    {
37
        if($value < self::VALUE_MIN) { $value = self::VALUE_MIN; }
38
        if($value > self::VALUE_MAX) { $value = self::VALUE_MAX; }
39
40
        $this->value = $value;
41
    }
42
43
    /**
44
     * @return int 0-255
45
     */
46
    public function getValue() : int
47
    {
48
        return $this->value;
49
    }
50
51
    public function get8Bit() : int
52
    {
53
        return $this->value;
54
    }
55
56
    public function get7Bit() : int
57
    {
58
        return UnitsConverter::intEightBit2IntSevenBit($this->value);
59
    }
60
61
    public function getAlpha() : float
62
    {
63
        return UnitsConverter::intEightBit2Alpha($this->value);
64
    }
65
66
    public function getPercent() : float
67
    {
68
        return UnitsConverter::intEightBit2Percent($this->value);
69
    }
70
71
    public function invert() : EightBitChannel
72
    {
73
        return ColorChannel::eightBit(255-$this->value);
74
    }
75
}
76