Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
7.69% covered (danger)
7.69%
1 / 13
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
EllipseShape
7.69% covered (danger)
7.69%
1 / 13
50.00% covered (danger)
50.00%
1 / 2
58.34
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 / 12
0.00% covered (danger)
0.00%
0 / 1
56
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Css\Value;
6
7/**
8 * `ellipse([<shape-radius> <shape-radius>]? [at <position>]?)`
9 * per CSS Shapes 1 ยง3.3. When both radii are omitted, defaults
10 * to two `closest-side` keywords (one per axis).
11 */
12final readonly class EllipseShape extends BasicShape
13{
14    public function __construct(
15        public ?Value $radiusX = null,
16        public ?Value $radiusY = null,
17        public ?Value $centerX = null,
18        public ?Value $centerY = null,
19    ) {}
20
21    public function toCss(): string
22    {
23        $parts = [];
24        if ($this->radiusX !== null && $this->radiusY !== null) {
25            $parts[] = $this->radiusX->toCss();
26            $parts[] = $this->radiusY->toCss();
27        }
28        if ($this->centerX !== null || $this->centerY !== null) {
29            $at = 'at';
30            if ($this->centerX !== null) {
31                $at .= ' ' . $this->centerX->toCss();
32            }
33            if ($this->centerY !== null) {
34                $at .= ' ' . $this->centerY->toCss();
35            }
36            $parts[] = $at;
37        }
38        return 'ellipse(' . implode(' ', $parts) . ')';
39    }
40}