Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| PolygonShape | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toCss | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Css\Value; |
| 6 | |
| 7 | /** |
| 8 | * `polygon([<fill-rule>]? <length-percentage> <length-percentage>, |
| 9 | * [<length-percentage> <length-percentage>]*)` per CSS |
| 10 | * Shapes 1 ยง3.4. Defines an arbitrary polygon by its vertices. |
| 11 | * |
| 12 | * `<fill-rule>` is `nonzero` (default) or `evenodd`. |
| 13 | */ |
| 14 | final readonly class PolygonShape extends BasicShape |
| 15 | { |
| 16 | /** |
| 17 | * @param string $fillRule 'nonzero' (default) or 'evenodd'. |
| 18 | * @param list<array{Value, Value}> $vertices Each entry is `[x, y]`. |
| 19 | */ |
| 20 | public function __construct( |
| 21 | public string $fillRule, |
| 22 | public array $vertices, |
| 23 | ) {} |
| 24 | |
| 25 | public function toCss(): string |
| 26 | { |
| 27 | $head = $this->fillRule === 'nonzero' ? '' : $this->fillRule . ', '; |
| 28 | $verts = implode(', ', array_map( |
| 29 | static fn(array $v): string => $v[0]->toCss() . ' ' . $v[1]->toCss(), |
| 30 | $this->vertices, |
| 31 | )); |
| 32 | return 'polygon(' . $head . $verts . ')'; |
| 33 | } |
| 34 | } |