Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
58.33% |
7 / 12 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| RectShape | |
58.33% |
7 / 12 |
|
50.00% |
1 / 2 |
3.65 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toCss | |
54.55% |
6 / 11 |
|
0.00% |
0 / 1 |
2.38 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Css\Value; |
| 6 | |
| 7 | /** |
| 8 | * `rect(<top> <right> <bottom> <left> [round <border-radius>]?)` |
| 9 | * per CSS Shapes 2 ยง4.5. Defines a clip rectangle by its |
| 10 | * top / right / bottom / left edges measured from the reference |
| 11 | * box origin (NOT inset distances like `inset()` uses). |
| 12 | * |
| 13 | * clip-path: rect(0 100% 100% 0); |
| 14 | * clip-path: rect(10px 90% 90% 10px round 5px); |
| 15 | * clip-path: rect(0 auto 100px 0); -- `auto` keyword |
| 16 | */ |
| 17 | final readonly class RectShape extends BasicShape |
| 18 | { |
| 19 | /** |
| 20 | * @param list<Value> $edges Top, right, bottom, left edges. |
| 21 | * Each is Length / Percentage / |
| 22 | * Keyword('auto'). |
| 23 | * @param ?list<Value> $borderRadius Optional rounded-corner values. |
| 24 | */ |
| 25 | public function __construct( |
| 26 | public array $edges, |
| 27 | public ?array $borderRadius = null, |
| 28 | ) {} |
| 29 | |
| 30 | public function toCss(): string |
| 31 | { |
| 32 | $edges = implode(' ', array_map( |
| 33 | static fn(Value $v): string => $v->toCss(), |
| 34 | $this->edges, |
| 35 | )); |
| 36 | if ($this->borderRadius === null) { |
| 37 | return 'rect(' . $edges . ')'; |
| 38 | } |
| 39 | $radius = implode(' ', array_map( |
| 40 | static fn(Value $v): string => $v->toCss(), |
| 41 | $this->borderRadius, |
| 42 | )); |
| 43 | return 'rect(' . $edges . ' round ' . $radius . ')'; |
| 44 | } |
| 45 | } |