Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
80.00% |
4 / 5 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| TypeSelector | |
80.00% |
4 / 5 |
|
66.67% |
2 / 3 |
4.13 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| specificity | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toString | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
2.15 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Css\Selector; |
| 6 | |
| 7 | /** |
| 8 | * Type selector per Selectors 4 §6: `tagname`, `*|tagname`, `ns|tagname`, |
| 9 | * `|tagname`. The universal selector `*` is represented by |
| 10 | * {@see UniversalSelector}. |
| 11 | * |
| 12 | * `namespacePrefix` semantics: |
| 13 | * - `null` — no `|`; matches in default namespace (or any namespace if no |
| 14 | * default-ns rule has been declared; the matcher resolves this). |
| 15 | * - `''` — explicit empty prefix `|tag`, matches only the null namespace. |
| 16 | * - `'*'` — `*|tag`, matches in any namespace. |
| 17 | * - any other string — matches the namespace registered for that prefix. |
| 18 | */ |
| 19 | final readonly class TypeSelector extends SimpleSelector |
| 20 | { |
| 21 | public function __construct( |
| 22 | public string $localName, |
| 23 | public ?string $namespacePrefix = null, |
| 24 | ) {} |
| 25 | |
| 26 | public function specificity(): Specificity |
| 27 | { |
| 28 | return new Specificity(0, 0, 1); |
| 29 | } |
| 30 | |
| 31 | public function toString(): string |
| 32 | { |
| 33 | if ($this->namespacePrefix === null) { |
| 34 | return $this->localName; |
| 35 | } |
| 36 | return $this->namespacePrefix . '|' . $this->localName; |
| 37 | } |
| 38 | } |