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
2/**
3 * @file
4 * @license https://opensource.org/licenses/Apache-2.0 Apache-2.0
5 */
6
7namespace Wikimedia\CSS\Grammar;
8
9use Wikimedia\CSS\Objects\ComponentValueList;
10use Wikimedia\CSS\Objects\Token;
11
12/**
13 * Matcher that matches a custom property (a CSS variable) example --name-of-variable
14 *
15 * This utilises regex to match the custom property --[a-zA-Z][a-zA-Z0-9-] without any input validation.
16 *
17 * @see https://www.w3.org/TR/2022/CR-css-variables-1-20220616/#custom-property
18 */
19class CustomPropertyMatcher extends Matcher {
20
21    /** @inheritDoc */
22    protected function generateMatches( ComponentValueList $values, $start, array $options ) {
23        $cv = $values[$start] ?? null;
24        if ( $cv instanceof Token && $cv->type() === Token::T_IDENT
25            && preg_match( '/^\-\-[a-zA-Z][a-zA-Z0-9-]*$/', $cv->value() ) ) {
26            yield $this->makeMatch( $values, $start, $this->next( $values, $start, $options ) );
27        }
28    }
29}