Total Complexity | 8 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | class HEX extends Color |
||
10 | { |
||
11 | private $red; |
||
12 | private $green; |
||
13 | private $blue; |
||
14 | |||
15 | 341 | public function __construct(string $red, string $green, string $blue) |
|
16 | { |
||
17 | 341 | $pattern = '/^[0-9a-f]{1,2}$/i'; |
|
18 | |||
19 | 341 | if (!preg_match($pattern, $red)) { |
|
20 | 4 | throw new InvalidArgumentException(sprintf('Given red value %s need so to be a valid 2 character hex string', $red)); |
|
21 | } |
||
22 | 337 | if (!preg_match($pattern, $green)) { |
|
23 | 4 | throw new InvalidArgumentException(sprintf('Given red value %s need so to be a valid 2 character hex string', $green)); |
|
24 | } |
||
25 | 333 | if (!preg_match($pattern, $blue)) { |
|
26 | 4 | throw new InvalidArgumentException(sprintf('Given red value %s need so to be a valid 2 character hex string', $blue)); |
|
27 | } |
||
28 | |||
29 | 329 | $this->red = $red; |
|
30 | 329 | $this->green = $green; |
|
31 | 329 | $this->blue = $blue; |
|
32 | 329 | } |
|
33 | |||
34 | 195 | public function __toString() |
|
37 | } |
||
38 | |||
39 | 133 | public function getRed(): string |
|
40 | { |
||
41 | 133 | return $this->red; |
|
42 | } |
||
43 | |||
44 | 133 | public function getGreen(): string |
|
45 | { |
||
46 | 133 | return $this->green; |
|
47 | } |
||
48 | |||
49 | 133 | public function getBlue(): string |
|
52 | } |
||
53 | } |
||
54 |