Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
TokenList
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 toTokenArray
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toComponentValueArray
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2/**
3 * @file
4 * @license https://opensource.org/licenses/Apache-2.0 Apache-2.0
5 */
6
7namespace Wikimedia\CSS\Objects;
8
9use UnexpectedValueException;
10use Wikimedia\CSS\Parser\Parser;
11
12/**
13 * Represent a list of CSS tokens
14 */
15class TokenList extends CSSObjectList {
16    /**
17     * @var string
18     */
19    protected static $objectType = Token::class;
20
21    /** @var Token[] The objects contained */
22    protected $objects;
23
24    /** @inheritDoc */
25    public function toTokenArray() {
26        // We can greatly simplify this, assuming no separator
27        return $this->objects;
28    }
29
30    /** @inheritDoc */
31    public function toComponentValueArray() {
32        // This one, though, is complicated
33        $parser = Parser::newFromTokens( $this->objects );
34        $ret = $parser->parseComponentValueList();
35        if ( $parser->getParseErrors() ) {
36            $ex = new UnexpectedValueException( 'TokenList cannot be converted to a ComponentValueList' );
37            // @phan-suppress-next-line PhanUndeclaredProperty
38            $ex->parseErrors = $parser->getParseErrors();
39            throw $ex;
40        }
41        return $ret->toComponentValueArray();
42    }
43}