Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
CmykColor
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
4 / 4
7
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
4
 toRgb
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toArray
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getColorSpace
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Color;
6
7/**
8 * CMYK color with components in 0.0–1.0 range — maps to PDF DeviceCMYK.
9 */
10final class CmykColor implements ColorInterface
11{
12    public function __construct(
13        public readonly float $c,
14        public readonly float $m,
15        public readonly float $y,
16        public readonly float $k,
17    ) {
18        foreach (['c' => $c, 'm' => $m, 'y' => $y, 'k' => $k] as $name => $value) {
19            if ($value < 0.0 || $value > 1.0) {
20                throw new \InvalidArgumentException("CMYK $name value must be 0.0–1.0, got $value");
21            }
22        }
23    }
24
25    public function toRgb(): RgbColor
26    {
27        return ColorConverter::cmykToRgb($this);
28    }
29
30    /** @return array<int, float> */
31    public function toArray(): array
32    {
33        return [$this->c, $this->m, $this->y, $this->k];
34    }
35
36    public function getColorSpace(): string
37    {
38        return 'DeviceCMYK';
39    }
40}