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