Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
7.14% covered (danger)
7.14%
1 / 14
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
RadialGradient
7.14% covered (danger)
7.14%
1 / 14
50.00% covered (danger)
50.00%
1 / 2
59.24
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toCss
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
56
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Css\Value;
6
7/**
8 * `radial-gradient([<shape> <size>] [at <position>], <stops>)`. Phase 1A.2-bis
9 * carries the parsed shape/sizing/position through; the renderer resolves
10 * them against the box at paint time.
11 */
12final readonly class RadialGradient extends Gradient
13{
14    /**
15     * @param list<GradientStop> $stops
16     */
17    public function __construct(
18        public GradientShape $shape,
19        public ?Length $sizeX,
20        public ?Length $sizeY,
21        public ?Length $centerX,
22        public ?Length $centerY,
23        public array $stops,
24        public bool $repeating = false,
25        public ?ColorSpace $interpolationSpace = null,
26        public ?HueInterpolation $hueInterpolation = null,
27    ) {}
28
29    public function toCss(): string
30    {
31        $prefix = $this->repeating ? 'repeating-radial-gradient' : 'radial-gradient';
32        $stops = implode(', ', array_map(static fn(GradientStop $s): string => $s->toCss(), $this->stops));
33        $shape = $this->shape === GradientShape::Circle ? 'circle' : 'ellipse';
34        $size = '';
35        if ($this->sizeX !== null) {
36            $size = ' ' . $this->sizeX->toCss();
37            if ($this->sizeY !== null) {
38                $size .= ' ' . $this->sizeY->toCss();
39            }
40        }
41        $position = '';
42        if ($this->centerX !== null && $this->centerY !== null) {
43            $position = ' at ' . $this->centerX->toCss() . ' ' . $this->centerY->toCss();
44        }
45        $method = InterpolationMethodCss::serialise($this->interpolationSpace, $this->hueInterpolation);
46        return sprintf('%s(%s%s%s%s, %s)', $prefix, $shape, $size, $position, $method, $stops);
47    }
48}