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