Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
70.59% |
12 / 17 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| InsetShape | |
70.59% |
12 / 17 |
|
50.00% |
1 / 2 |
4.41 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toCss | |
68.75% |
11 / 16 |
|
0.00% |
0 / 1 |
3.27 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Css\Value; |
| 6 | |
| 7 | /** |
| 8 | * `inset(<length-percentage>{1,4} [round <border-radius>]?)` per |
| 9 | * CSS Shapes 1 §3.1. Defines a rectangular shape inset from the |
| 10 | * reference box by 1-4 lengths (TRBL clockwise) with optional |
| 11 | * rounded corners. |
| 12 | */ |
| 13 | final readonly class InsetShape extends BasicShape |
| 14 | { |
| 15 | /** |
| 16 | * @param list<Value> $insets 1 to 4 Length / Percentage values |
| 17 | * (top [right [bottom [left]]]). |
| 18 | * @param ?list<Value> $borderRadius Optional rounded-corner values |
| 19 | * parsed as a CSS border-radius |
| 20 | * value list; null when the |
| 21 | * `round` keyword was absent. |
| 22 | * These are the HORIZONTAL radii |
| 23 | * when the two-axis `/` form is |
| 24 | * used. |
| 25 | * @param ?list<Value> $borderRadiusVertical The VERTICAL radii of |
| 26 | * the `a / b` two-axis form |
| 27 | * (CSS Backgrounds 3 §5.5), or |
| 28 | * null when the author wrote a |
| 29 | * single list and each value |
| 30 | * applies to both axes. Kept |
| 31 | * separate rather than |
| 32 | * concatenated because the two |
| 33 | * groups are independently 1-4 |
| 34 | * values long and a flat list |
| 35 | * cannot say where the split was. |
| 36 | */ |
| 37 | public function __construct( |
| 38 | public array $insets, |
| 39 | public ?array $borderRadius = null, |
| 40 | public ?array $borderRadiusVertical = null, |
| 41 | ) {} |
| 42 | |
| 43 | public function toCss(): string |
| 44 | { |
| 45 | $insets = implode(' ', array_map( |
| 46 | static fn(Value $v): string => $v->toCss(), |
| 47 | $this->insets, |
| 48 | )); |
| 49 | if ($this->borderRadius === null) { |
| 50 | return 'inset(' . $insets . ')'; |
| 51 | } |
| 52 | $radius = implode(' ', array_map( |
| 53 | static fn(Value $v): string => $v->toCss(), |
| 54 | $this->borderRadius, |
| 55 | )); |
| 56 | if ($this->borderRadiusVertical !== null) { |
| 57 | $radius .= ' / ' . implode(' ', array_map( |
| 58 | static fn(Value $v): string => $v->toCss(), |
| 59 | $this->borderRadiusVertical, |
| 60 | )); |
| 61 | } |
| 62 | return 'inset(' . $insets . ' round ' . $radius . ')'; |
| 63 | } |
| 64 | } |