Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
90.57% covered (success)
90.57%
48 / 53
72.73% covered (warning)
72.73%
8 / 11
CRAP
0.00% covered (danger)
0.00%
0 / 1
Less_Tree_AtRule
90.57% covered (success)
90.57%
48 / 53
72.73% covered (warning)
72.73%
8 / 11
26.57
0.00% covered (danger)
0.00%
0 / 1
 __construct
92.86% covered (success)
92.86%
13 / 14
0.00% covered (danger)
0.00%
0 / 1
4.01
 accept
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
 isRulesetLike
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 isCharset
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 genCSS
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
3
 compile
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
1 / 1
3
 variable
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
 find
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
 markReferenced
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 getIsReferenced
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
3
 emptySelectors
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * @private
4 * @see less-3.13.1.js#AtRule.prototype
5 */
6class Less_Tree_AtRule extends Less_Tree implements Less_Tree_HasValueProperty {
7    public $name;
8    public $value;
9    public $rules;
10    public $index;
11    public $isReferenced;
12    public $isRooted;
13    public $currentFileInfo;
14    public $debugInfo;
15
16    public function __construct( $name, $value = null, $rules = null, $index = null, $isRooted = false, $currentFileInfo = null, $debugInfo = null, $isReferenced = false ) {
17        $this->name = $name;
18        // TODO: Less.js 3.13 handles `$value instanceof Less_Tree` and creates Anonymous here.
19        $this->value = $value;
20
21        if ( $rules !== null ) {
22            if ( is_array( $rules ) ) {
23                $this->rules = $rules;
24            } else {
25                $this->rules = [ $rules ];
26                $this->rules[0]->selectors = $this->emptySelectors();
27            }
28
29            foreach ( $this->rules as $rule ) {
30                $rule->allowImports = true;
31            }
32            // TODO: Less.js 3.13 handles setParent() here
33        }
34
35        $this->index = $index;
36        $this->isRooted = $isRooted;
37        $this->currentFileInfo = $currentFileInfo;
38        $this->debugInfo = $debugInfo;
39        $this->isReferenced = $isReferenced;
40    }
41
42    public function accept( $visitor ) {
43        if ( $this->rules ) {
44            $this->rules = $visitor->visitArray( $this->rules );
45        }
46        if ( $this->value ) {
47            $this->value = $visitor->visitObj( $this->value );
48        }
49    }
50
51    public function isRulesetLike() {
52        return $this->rules || !$this->isCharset();
53    }
54
55    public function isCharset() {
56        return $this->name === "@charset";
57    }
58
59    /**
60     * @see Less_Tree::genCSS
61     */
62    public function genCSS( $output ) {
63        $output->add( $this->name, $this->currentFileInfo, $this->index );
64        if ( $this->value ) {
65            $output->add( ' ' );
66            $this->value->genCSS( $output );
67        }
68        if ( $this->rules !== null ) {
69            Less_Tree::outputRuleset( $output, $this->rules );
70        } else {
71            $output->add( ';' );
72        }
73    }
74
75    public function compile( $env ) {
76        $value = $this->value;
77        $rules = $this->rules;
78
79        // Media stored inside other directive should not bubble over it
80        // backup media bubbling information
81        $mediaPathBackup = $env->mediaPath;
82        $mediaPBlocksBackup = $env->mediaBlocks;
83        // Deleted media bubbling information
84        $env->mediaPath = [];
85        $env->mediaBlocks = [];
86
87        if ( $value ) {
88            $value = $value->compile( $env );
89        }
90
91        if ( $rules ) {
92            // Assuming that there is only one rule at this point - that is how parser constructs the rule
93            $rules = $rules[0]->compile( $env );
94            $rules->root = true;
95        }
96
97        // Restore media bubbling information
98        $env->mediaPath = $mediaPathBackup;
99        $env->mediaBlocks = $mediaPBlocksBackup;
100
101        return new self( $this->name, $value, $rules, $this->index, $this->isRooted, $this->currentFileInfo, $this->debugInfo, $this->isReferenced );
102    }
103
104    public function variable( $name ) {
105        if ( $this->rules ) {
106            return $this->rules[0]->variable( $name );
107        }
108    }
109
110    public function find( $selector ) {
111        // TODO: Less.js 3.13.1 adds multiple variadic arguments here
112        if ( $this->rules ) {
113            return $this->rules[0]->find( $selector, $this );
114        }
115    }
116
117    // TODO: Implement less-3.13.1.js#AtRule.prototype.rulesets
118    // Unused?
119
120    // TODO: Implement less-3.13.1.js#AtRule.prototype.outputRuleset
121    // We have ours in Less_Tree::outputRuleset instead.
122
123    public function markReferenced() {
124        $this->isReferenced = true;
125        if ( $this->rules ) {
126            Less_Tree::ReferencedArray( $this->rules );
127        }
128    }
129
130    public function getIsReferenced() {
131        return !isset( $this->currentFileInfo['reference'] ) || !$this->currentFileInfo['reference'] || $this->isReferenced;
132    }
133
134    public function emptySelectors() {
135        $el = new Less_Tree_Element( '', '&', $this->index, $this->currentFileInfo );
136        $sels = [ new Less_Tree_Selector( [ $el ], [], null, $this->index, $this->currentFileInfo ) ];
137        $sels[0]->mediaEmpty = true;
138        return $sels;
139    }
140
141}