@@ 12-35 (lines=24) @@ | ||
9 | use Artack\Color\Color\RGB; |
|
10 | use Webmozart\Assert\Assert; |
|
11 | ||
12 | class HEXToRGBConverter implements Convertible |
|
13 | { |
|
14 | public function convert(Color $color): Color |
|
15 | { |
|
16 | /* @var HEX $color */ |
|
17 | Assert::isInstanceOf($color, HEX::class, sprintf('color should be an instance of [%s]', HEX::class)); |
|
18 | ||
19 | $red = hexdec($color->getRed()); |
|
20 | $green = hexdec($color->getGreen()); |
|
21 | $blue = hexdec($color->getBlue()); |
|
22 | ||
23 | return new RGB($red, $green, $blue); |
|
24 | } |
|
25 | ||
26 | public static function supportsFrom(): string |
|
27 | { |
|
28 | return HEX::class; |
|
29 | } |
|
30 | ||
31 | public static function supportsTo(): string |
|
32 | { |
|
33 | return RGB::class; |
|
34 | } |
|
35 | } |
|
36 |
@@ 12-35 (lines=24) @@ | ||
9 | use Artack\Color\Color\RGB; |
|
10 | use Webmozart\Assert\Assert; |
|
11 | ||
12 | class RGBToHEXConverter implements Convertible |
|
13 | { |
|
14 | public function convert(Color $color): Color |
|
15 | { |
|
16 | /* @var RGB $color */ |
|
17 | Assert::isInstanceOf($color, RGB::class, sprintf('color should be an instance of [%s]', RGB::class)); |
|
18 | ||
19 | $red = dechex($color->getRed()); |
|
20 | $green = dechex($color->getGreen()); |
|
21 | $blue = dechex($color->getBlue()); |
|
22 | ||
23 | return new HEX($red, $green, $blue); |
|
24 | } |
|
25 | ||
26 | public static function supportsFrom(): string |
|
27 | { |
|
28 | return RGB::class; |
|
29 | } |
|
30 | ||
31 | public static function supportsTo(): string |
|
32 | { |
|
33 | return HEX::class; |
|
34 | } |
|
35 | } |
|
36 |