Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
7 / 7
CRAP
100.00% covered (success)
100.00%
1 / 1
Stylesheet
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
7 / 7
8
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 __clone
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getRuleList
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getPosition
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 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%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __toString
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
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\Objects;
10
11use Wikimedia\CSS\Util;
12
13/**
14 * Represent a stylesheet
15 * @note This isn't necessarily a "CSS stylesheet" though.
16 * @warning If you're not using the provided Sanitizer classes to further sanitize
17 *  the CSS, you'll want to manually filter out any at-rules named "charset"
18 *  before stringifying and/or prepend `@charset "utf-8";` after stringifying
19 *  this object.
20 */
21class Stylesheet implements CSSObject {
22
23    /** @var RuleList */
24    protected $ruleList;
25
26    /**
27     * @param RuleList|null $rules
28     */
29    public function __construct( ?RuleList $rules = null ) {
30        $this->ruleList = $rules ?: new RuleList();
31    }
32
33    public function __clone() {
34        $this->ruleList = clone $this->ruleList;
35    }
36
37    /**
38     * @return RuleList
39     */
40    public function getRuleList() {
41        return $this->ruleList;
42    }
43
44    /** @inheritDoc */
45    public function getPosition() {
46        // Stylesheets don't really have a position
47        return [ 0, 0 ];
48    }
49
50    /** @inheritDoc */
51    public function toTokenArray() {
52        return $this->ruleList->toTokenArray();
53    }
54
55    /** @inheritDoc */
56    public function toComponentValueArray() {
57        return $this->ruleList->toComponentValueArray();
58    }
59
60    public function __toString() {
61        return Util::stringify( $this );
62    }
63}