Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
83.33% |
5 / 6 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| SelectorList | |
83.33% |
5 / 6 |
|
66.67% |
2 / 3 |
4.07 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isEmpty | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| toString | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Css\Selector; |
| 6 | |
| 7 | /** |
| 8 | * A comma-separated list of selectors per CSS Selectors 4 §3.4. |
| 9 | * |
| 10 | * `selectors` is the parsed list of `ComplexSelector`s. `text` keeps the |
| 11 | * original prelude source for diagnostics / serialization. Parser errors |
| 12 | * inside one selector cause that selector to be dropped per Selectors 4 |
| 13 | * §3.7 forgiving / non-forgiving rules — the consumer (parser or pseudo- |
| 14 | * class like `:is()` / `:where()`) decides which mode to apply. |
| 15 | */ |
| 16 | final readonly class SelectorList |
| 17 | { |
| 18 | /** @param list<ComplexSelector> $selectors */ |
| 19 | public function __construct( |
| 20 | public string $text, |
| 21 | public array $selectors = [], |
| 22 | ) {} |
| 23 | |
| 24 | public function isEmpty(): bool |
| 25 | { |
| 26 | return $this->selectors === []; |
| 27 | } |
| 28 | |
| 29 | public function toString(): string |
| 30 | { |
| 31 | $parts = []; |
| 32 | foreach ($this->selectors as $sel) { |
| 33 | $parts[] = $sel->toString(); |
| 34 | } |
| 35 | return implode(', ', $parts); |
| 36 | } |
| 37 | } |