Debian Codegraph @

vendor/wikimedia/css-sanitizer/src/Objects/ComponentValueList.php

raw
1 <?php
2 /**
3 * @file
4 * @license https://opensource.org/licenses/Apache-2.0 Apache-2.0
5 */
6
7 namespace Wikimedia\CSS\Objects;
8
9 use InvalidArgumentException;
10
11 /**
12 * Represent a list of CSS component values, eg. `10px 20px` is the
13 * component value list in the declaration `margin: 10px 20px;`.
14 * @extends CSSObjectList<ComponentValue>
15 */
16 class ComponentValueList extends CSSObjectList {
17 /**
18 * @var string
19 */
20 protected static $objectType = ComponentValue::class;
21
22 /** @inheritDoc */
23 protected static function testObjects( array $objects ) {
24 foreach ( $objects as $object ) {
25 $type = $object instanceof Token ? $object->type() : 'n/a';
26 switch ( $type ) {
27 case Token::T_FUNCTION:
28 case Token::T_LEFT_BRACKET:
29 case Token::T_LEFT_PAREN:
30 case Token::T_LEFT_BRACE:
31 throw new InvalidArgumentException(
32 static::class . " may not contain tokens of type \"$type\"."
33 );
34 }
35 }
36 }
37
38 /** @inheritDoc */
39 public function toComponentValueArray() {
40 // Much simpler
41 return $this->objects;
42 }
43 }