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

EightBitChannel   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 13
c 1
b 0
f 0
dl 0
loc 49
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 3 1
A getPercent() 0 3 1
A get8Bit() 0 3 1
A getAlpha() 0 3 1
A invert() 0 3 1
A __construct() 0 6 3
A get7Bit() 0 3 1
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