Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Alternative
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
2 / 2
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 generateMatches
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2declare( strict_types = 1 );
3
4/**
5 * @file
6 * @license https://opensource.org/licenses/Apache-2.0 Apache-2.0
7 */
8
9namespace Wikimedia\CSS\Grammar;
10
11use Wikimedia\CSS\Objects\ComponentValueList;
12use Wikimedia\CSS\Util;
13
14/**
15 * Matcher that matches one out of a set of Matchers ("|" combiner).
16 * @see https://www.w3.org/TR/2024/WD-css-values-4-20240312/#comb-one
17 */
18class Alternative extends Matcher {
19    /** @var Matcher[] */
20    protected $matchers;
21
22    /**
23     * @param Matcher[] $matchers
24     */
25    public function __construct( array $matchers ) {
26        Util::assertAllInstanceOf( $matchers, Matcher::class, '$matchers' );
27        $this->matchers = $matchers;
28    }
29
30    /** @inheritDoc */
31    protected function generateMatches( ComponentValueList $values, $start, array $options ) {
32        $used = [];
33        foreach ( $this->matchers as $matcher ) {
34            foreach ( $matcher->generateMatches( $values, $start, $options ) as $match ) {
35                $newMatch = $this->makeMatch( $values, $start, $match->getNext(), $match );
36                $mid = $newMatch->getUniqueID();
37                if ( !isset( $used[$mid] ) ) {
38                    $used[$mid] = 1;
39                    yield $newMatch;
40                }
41            }
42        }
43    }
44}