Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
20.00% |
1 / 5 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| LinearGradient | |
20.00% |
1 / 5 |
|
50.00% |
1 / 2 |
12.19 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toCss | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace 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 | */ |
| 12 | final readonly class LinearGradient extends Gradient |
| 13 | { |
| 14 | /** @param list<GradientStop> $stops */ |
| 15 | public function __construct(public float $angleDeg, public array $stops, public bool $repeating = false) {} |
| 16 | |
| 17 | public function toCss(): string |
| 18 | { |
| 19 | $prefix = $this->repeating ? 'repeating-linear-gradient' : 'linear-gradient'; |
| 20 | $stops = implode(', ', array_map(static fn(GradientStop $s): string => $s->toCss(), $this->stops)); |
| 21 | $angle = (fmod($this->angleDeg, 1.0) === 0.0 ? (int) $this->angleDeg : $this->angleDeg) . 'deg'; |
| 22 | return sprintf('%s(%s, %s)', $prefix, $angle, $stops); |
| 23 | } |
| 24 | } |