Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
CompoundSelector
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
3 / 3
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 specificity
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 toString
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Css\Selector;
6
7/**
8 * A compound selector per Selectors 4 ยง3.5: a sequence of simple selectors
9 * with no intervening whitespace. Matches one element if every component
10 * matches.
11 *
12 * Pseudo-elements (when present) must be the last simple selector in the
13 * compound and are not interleaved with other simple selectors per spec.
14 */
15final readonly class CompoundSelector
16{
17    /** @param list<SimpleSelector> $components */
18    public function __construct(public array $components) {}
19
20    public function specificity(): Specificity
21    {
22        $total = new Specificity();
23        foreach ($this->components as $c) {
24            $total = $total->add($c->specificity());
25        }
26        return $total;
27    }
28
29    public function toString(): string
30    {
31        $out = '';
32        foreach ($this->components as $c) {
33            $out .= $c->toString();
34        }
35        return $out;
36    }
37}