Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
LinearGradient
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toCss
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Css\Value;
6
7/**
8 * `linear-gradient(<angle> | to <side>, <stops>)`. The angle is stored in
9 * degrees normalised to [0, 360). When the input used `to <side>` (e.g.
10 * `to right`) the parser converts it to the equivalent angle.
11 */
12final readonly class LinearGradient extends Gradient
13{
14    /** @param list<GradientStop> $stops */
15    public function __construct(
16        public float $angleDeg,
17        public array $stops,
18        public bool $repeating = false,
19        public ?ColorSpace $interpolationSpace = null,
20        public ?HueInterpolation $hueInterpolation = null,
21    ) {}
22
23    public function toCss(): string
24    {
25        $prefix = $this->repeating ? 'repeating-linear-gradient' : 'linear-gradient';
26        $stops = implode(', ', array_map(static fn(GradientStop $s): string => $s->toCss(), $this->stops));
27        $angle = (fmod($this->angleDeg, 1.0) === 0.0 ? (int) $this->angleDeg : $this->angleDeg) . 'deg';
28        $head = $angle . InterpolationMethodCss::serialise($this->interpolationSpace, $this->hueInterpolation);
29        return sprintf('%s(%s, %s)', $prefix, $head, $stops);
30    }
31}