Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
91.67% |
11 / 12 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| InsetShape | |
91.67% |
11 / 12 |
|
50.00% |
1 / 2 |
3.01 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toCss | |
90.91% |
10 / 11 |
|
0.00% |
0 / 1 |
2.00 | |||
| 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 | */ |
| 23 | public function __construct( |
| 24 | public array $insets, |
| 25 | public ?array $borderRadius = null, |
| 26 | ) {} |
| 27 | |
| 28 | public function toCss(): string |
| 29 | { |
| 30 | $insets = implode(' ', array_map( |
| 31 | static fn(Value $v): string => $v->toCss(), |
| 32 | $this->insets, |
| 33 | )); |
| 34 | if ($this->borderRadius === null) { |
| 35 | return 'inset(' . $insets . ')'; |
| 36 | } |
| 37 | $radius = implode(' ', array_map( |
| 38 | static fn(Value $v): string => $v->toCss(), |
| 39 | $this->borderRadius, |
| 40 | )); |
| 41 | return 'inset(' . $insets . ' round ' . $radius . ')'; |
| 42 | } |
| 43 | } |