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_Directive
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-2.5.3.js#Anonymous.prototype
5 */
6class Less_Tree_Directive 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        $this->value = $value;
19
20        if ( $rules !== null ) {
21            if ( is_array( $rules ) ) {
22                $this->rules = $rules;
23            } else {
24                $this->rules = [ $rules ];
25                $this->rules[0]->selectors = $this->emptySelectors();
26            }
27
28            foreach ( $this->rules as $rule ) {
29                $rule->allowImports = true;
30            }
31        }
32
33        $this->index = $index;
34        $this->isRooted = $isRooted;
35        $this->currentFileInfo = $currentFileInfo;
36        $this->debugInfo = $debugInfo;
37        $this->isReferenced = $isReferenced;
38    }
39
40    public function accept( $visitor ) {
41        if ( $this->rules ) {
42            $this->rules = $visitor->visitArray( $this->rules );
43        }
44        if ( $this->value ) {
45            $this->value = $visitor->visitObj( $this->value );
46        }
47    }
48
49    public function isRulesetLike() {
50        return $this->rules || !$this->isCharset();
51    }
52
53    public function isCharset() {
54        return $this->name === "@charset";
55    }
56
57    /**
58     * @see Less_Tree::genCSS
59     */
60    public function genCSS( $output ) {
61        $output->add( $this->name, $this->currentFileInfo, $this->index );
62        if ( $this->value ) {
63            $output->add( ' ' );
64            $this->value->genCSS( $output );
65        }
66        if ( $this->rules !== null ) {
67            Less_Tree::outputRuleset( $output, $this->rules );
68        } else {
69            $output->add( ';' );
70        }
71    }
72
73    public function compile( $env ) {
74        $value = $this->value;
75        $rules = $this->rules;
76
77        // Media stored inside other directive should not bubble over it
78        // backup media bubbling information
79        $mediaPathBackup = $env->mediaPath;
80        $mediaPBlocksBackup = $env->mediaBlocks;
81        // Deleted media bubbling information
82        $env->mediaPath = [];
83        $env->mediaBlocks = [];
84
85        if ( $value ) {
86            $value = $value->compile( $env );
87        }
88
89        if ( $rules ) {
90            // Assuming that there is only one rule at this point - that is how parser constructs the rule
91            $rules = $rules[0]->compile( $env );
92            $rules->root = true;
93        }
94
95        // Restore media bubbling information
96        $env->mediaPath = $mediaPathBackup;
97        $env->mediaBlocks = $mediaPBlocksBackup;
98
99        return new self( $this->name, $value, $rules, $this->index, $this->isRooted, $this->currentFileInfo, $this->debugInfo, $this->isReferenced );
100    }
101
102    public function variable( $name ) {
103        if ( $this->rules ) {
104            return $this->rules[0]->variable( $name );
105        }
106    }
107
108    public function find( $selector ) {
109        if ( $this->rules ) {
110            return $this->rules[0]->find( $selector, $this );
111        }
112    }
113
114    public function markReferenced() {
115        $this->isReferenced = true;
116        if ( $this->rules ) {
117            Less_Tree::ReferencedArray( $this->rules );
118        }
119    }
120
121    public function getIsReferenced() {
122        return !isset( $this->currentFileInfo['reference'] ) || !$this->currentFileInfo['reference'] || $this->isReferenced;
123    }
124
125    public function emptySelectors() {
126        $el = new Less_Tree_Element( '', '&', $this->index, $this->currentFileInfo );
127        $sels = [ new Less_Tree_Selector( [ $el ], [], null, $this->index, $this->currentFileInfo ) ];
128        $sels[0]->mediaEmpty = true;
129        return $sels;
130    }
131
132}