Total Complexity | 6 |
Total Lines | 31 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
12 | class RGBToCMYKConverter implements ConverterInterface |
||
13 | { |
||
14 | 65 | public function convert(Color $color): Color |
|
15 | { |
||
16 | /* @var RGB $color */ |
||
17 | 65 | Assert::isInstanceOf($color, RGB::class, sprintf('color should be an instance of [%s]', RGB::class)); |
|
18 | |||
19 | 65 | $red = $color->getRed() / 255 * 100; |
|
20 | 65 | $green = $color->getGreen() / 255 * 100; |
|
21 | 65 | $blue = $color->getBlue() / 255 * 100; |
|
22 | |||
23 | 65 | if (0 === $red && 0 === $green && 0 === $blue) { |
|
24 | 1 | return new CMYK(0, 0, 0, 100); |
|
25 | } |
||
26 | |||
27 | 64 | $key = 100 - max($red, $green, $blue); |
|
28 | 64 | $cyan = ((100 - $red - $key) / (100 - $key)) * 100; |
|
29 | 64 | $magenta = ((100 - $green - $key) / (100 - $key)) * 100; |
|
30 | 64 | $yellow = ((100 - $blue - $key) / (100 - $key)) * 100; |
|
31 | |||
32 | 64 | return new CMYK($cyan, $magenta, $yellow, $key); |
|
33 | } |
||
34 | |||
35 | 924 | public static function supportsFrom(): string |
|
36 | { |
||
37 | 924 | return RGB::class; |
|
38 | } |
||
39 | |||
40 | 924 | public static function supportsTo(): string |
|
43 | } |
||
44 | } |
||
45 |