Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
7.69% |
1 / 13 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| RadialGradient | |
7.69% |
1 / 13 |
|
50.00% |
1 / 2 |
58.34 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toCss | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
56 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace 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 | */ |
| 12 | final 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 | ) {} |
| 26 | |
| 27 | public function toCss(): string |
| 28 | { |
| 29 | $prefix = $this->repeating ? 'repeating-radial-gradient' : 'radial-gradient'; |
| 30 | $stops = implode(', ', array_map(static fn(GradientStop $s): string => $s->toCss(), $this->stops)); |
| 31 | $shape = $this->shape === GradientShape::Circle ? 'circle' : 'ellipse'; |
| 32 | $size = ''; |
| 33 | if ($this->sizeX !== null) { |
| 34 | $size = ' ' . $this->sizeX->toCss(); |
| 35 | if ($this->sizeY !== null) { |
| 36 | $size .= ' ' . $this->sizeY->toCss(); |
| 37 | } |
| 38 | } |
| 39 | $position = ''; |
| 40 | if ($this->centerX !== null && $this->centerY !== null) { |
| 41 | $position = ' at ' . $this->centerX->toCss() . ' ' . $this->centerY->toCss(); |
| 42 | } |
| 43 | return sprintf('%s(%s%s%s, %s)', $prefix, $shape, $size, $position, $stops); |
| 44 | } |
| 45 | } |