Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
CustomPropertyMatcher
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
1 / 1
 generateMatches
100.00% covered (success)
100.00%
4 / 4
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\Objects\Token;
13
14/**
15 * Matcher that matches a custom property (a CSS variable) example --name-of-variable
16 *
17 * This utilises regex to match the custom property --[a-zA-Z][a-zA-Z0-9-] without any input validation.
18 *
19 * @see https://www.w3.org/TR/2022/CR-css-variables-1-20220616/#custom-property
20 */
21class CustomPropertyMatcher extends Matcher {
22
23    /** @inheritDoc */
24    protected function generateMatches( ComponentValueList $values, $start, array $options ) {
25        $cv = $values[$start] ?? null;
26        if ( $cv instanceof Token && $cv->type() === Token::T_IDENT
27            && preg_match( '/^\-\-[a-zA-Z][a-zA-Z0-9-]*$/', $cv->value() ) ) {
28            yield $this->makeMatch( $values, $start, $this->next( $values, $start, $options ) );
29        }
30    }
31}