Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
GrayColor
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
6 / 6
8
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
3
 black
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 white
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 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 * Grayscale color (0.0 = black, 1.0 = white) — maps to PDF DeviceGray.
9 */
10final class GrayColor implements ColorInterface
11{
12    public function __construct(
13        public readonly float $gray,
14    ) {
15        if ($gray < 0.0 || $gray > 1.0) {
16            throw new \InvalidArgumentException("Gray value must be 0.0–1.0, got $gray");
17        }
18    }
19
20    public static function black(): self
21    {
22        return new self(0.0);
23    }
24
25    public static function white(): self
26    {
27        return new self(1.0);
28    }
29
30    public function toRgb(): RgbColor
31    {
32        return ColorConverter::grayToRgb($this);
33    }
34
35    /** @return array<int, float> */
36    public function toArray(): array
37    {
38        return [$this->gray];
39    }
40
41    public function getColorSpace(): string
42    {
43        return 'DeviceGray';
44    }
45}