Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
CircleShape
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
2 / 2
7
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%
11 / 11
100.00% covered (success)
100.00%
1 / 1
6
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Css\Value;
6
7/**
8 * `circle([<shape-radius>] [at <position>]?)` per CSS Shapes 1
9 * §3.2. The radius defaults to `closest-side` when omitted; the
10 * position defaults to `center` (50% 50%) when omitted.
11 */
12final readonly class CircleShape extends BasicShape
13{
14    public function __construct(
15        /**
16         * Radius — Length / Percentage / Keyword('closest-side') /
17         * Keyword('farthest-side'). Null = `closest-side`
18         * default.
19         */
20        public ?Value $radius = null,
21        /**
22         * Center x position. Null = 50% default.
23         */
24        public ?Value $centerX = null,
25        /**
26         * Center y position. Null = 50% default.
27         */
28        public ?Value $centerY = null,
29    ) {}
30
31    public function toCss(): string
32    {
33        $parts = [];
34        if ($this->radius !== null) {
35            $parts[] = $this->radius->toCss();
36        }
37        if ($this->centerX !== null || $this->centerY !== null) {
38            $at = 'at';
39            if ($this->centerX !== null) {
40                $at .= ' ' . $this->centerX->toCss();
41            }
42            if ($this->centerY !== null) {
43                $at .= ' ' . $this->centerY->toCss();
44            }
45            $parts[] = $at;
46        }
47        return 'circle(' . implode(' ', $parts) . ')';
48    }
49}