Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
95.92% |
47 / 49 |
|
71.43% |
5 / 7 |
CRAP | |
0.00% |
0 / 1 |
Less_Tree_Expression | |
95.92% |
47 / 49 |
|
71.43% |
5 / 7 |
36 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
accept | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
compile | |
100.00% |
21 / 21 |
|
100.00% |
1 / 1 |
17 | |||
genCSS | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
4 | |||
throwAwayComments | |
85.71% |
6 / 7 |
|
0.00% |
0 / 1 |
4.05 | |||
markReferenced | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
4 | |||
mapToFunctionCallArgument | |
88.89% |
8 / 9 |
|
0.00% |
0 / 1 |
5.03 |
1 | <?php |
2 | /** |
3 | * @private |
4 | * @see less-3.13.1.js#Expression.prototype |
5 | */ |
6 | class Less_Tree_Expression extends Less_Tree implements Less_Tree_HasValueProperty { |
7 | |
8 | /** @var Less_Tree[] */ |
9 | public $value = []; |
10 | |
11 | public $noSpacing; |
12 | public $parens = null; |
13 | |
14 | public function __construct( $value, $noSpacing = false ) { |
15 | $this->value = $value; |
16 | $this->noSpacing = $noSpacing; |
17 | } |
18 | |
19 | public function accept( $visitor ) { |
20 | $this->value = $visitor->visitArray( $this->value ); |
21 | } |
22 | |
23 | public function compile( $env ) { |
24 | $mathOn = $env->isMathOn(); |
25 | // NOTE: We don't support STRICT_LEGACY (Less.js 3.13) |
26 | $inParenthesis = $this->parens && ( true || !$this->parensInOp ); |
27 | $doubleParen = false; |
28 | if ( $inParenthesis ) { |
29 | $env->inParenthesis(); |
30 | } |
31 | |
32 | if ( $this->value ) { |
33 | |
34 | if ( count( $this->value ) > 1 ) { |
35 | $ret = []; |
36 | foreach ( $this->value as $e ) { |
37 | $ret[] = $e->compile( $env ); |
38 | } |
39 | $returnValue = new self( $ret, $this->noSpacing ); |
40 | |
41 | } else { |
42 | // Implied `if ( count() === 1 )` |
43 | if ( ( $this->value[0] instanceof self ) && $this->value[0]->parens && !$this->value[0]->parensInOp && !$env->inCalc ) { |
44 | $doubleParen = true; |
45 | } |
46 | $returnValue = $this->value[0]->compile( $env ); |
47 | } |
48 | } else { |
49 | $returnValue = $this; |
50 | } |
51 | |
52 | if ( $inParenthesis ) { |
53 | $env->outOfParenthesis(); |
54 | } |
55 | |
56 | if ( $this->parens && $this->parensInOp && !$mathOn && !$doubleParen && |
57 | ( !( $returnValue instanceof Less_Tree_Dimension ) ) |
58 | ) { |
59 | $returnValue = new Less_Tree_Paren( $returnValue ); |
60 | } |
61 | return $returnValue; |
62 | } |
63 | |
64 | /** |
65 | * @see Less_Tree::genCSS |
66 | */ |
67 | public function genCSS( $output ) { |
68 | $val_len = count( $this->value ); |
69 | for ( $i = 0; $i < $val_len; $i++ ) { |
70 | $this->value[$i]->genCSS( $output ); |
71 | if ( !$this->noSpacing && ( $i + 1 < $val_len ) ) { |
72 | $output->add( ' ' ); |
73 | } |
74 | } |
75 | } |
76 | |
77 | public function throwAwayComments() { |
78 | if ( is_array( $this->value ) ) { |
79 | $new_value = []; |
80 | foreach ( $this->value as $v ) { |
81 | if ( $v instanceof Less_Tree_Comment ) { |
82 | continue; |
83 | } |
84 | $new_value[] = $v; |
85 | } |
86 | $this->value = $new_value; |
87 | } |
88 | } |
89 | |
90 | public function markReferenced() { |
91 | if ( is_array( $this->value ) ) { |
92 | foreach ( $this->value as $v ) { |
93 | if ( method_exists( $v, 'markReferenced' ) ) { |
94 | $v->markReferenced(); |
95 | } |
96 | } |
97 | } |
98 | } |
99 | |
100 | /** |
101 | * Should be used only in Less_Tree_Call::functionCaller() |
102 | * to retrieve expression without comments |
103 | * @internal |
104 | */ |
105 | public function mapToFunctionCallArgument() { |
106 | if ( is_array( $this->value ) ) { |
107 | $subNodes = []; |
108 | foreach ( $this->value as $subNode ) { |
109 | if ( !( $subNode instanceof Less_Tree_Comment ) ) { |
110 | $subNodes[] = $subNode; |
111 | } |
112 | } |
113 | return count( $subNodes ) === 1 |
114 | ? $subNodes[0] |
115 | : new Less_Tree_Expression( $subNodes ); |
116 | } |
117 | return $this; |
118 | } |
119 | } |