Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
54.55% covered (warning)
54.55%
12 / 22
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
Less_Tree_VariableCall
54.55% covered (warning)
54.55%
12 / 22
66.67% covered (warning)
66.67%
2 / 3
32.41
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
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
44.44% covered (danger)
44.44%
8 / 18
0.00% covered (danger)
0.00%
0 / 1
36.69
1<?php
2declare( strict_types = 1 );
3
4/**
5 * @private
6 * @see less-3.13.1.js#VariableCall
7 * @todo missing allowRoot implementation https://github.com/less/less.js/commit/b67403d3
8 */
9class Less_Tree_VariableCall extends Less_Tree {
10
11    /** @var string */
12    public $variable;
13    /** @var string */
14    public $type = "VariableCall";
15    /**
16     * @var int
17     */
18    private $index;
19    /**
20     * @var array
21     */
22    private $currentFileInfo;
23
24    /**
25     * @param string $variable
26     */
27    public function __construct( $variable, $index, $currentFileInfo ) {
28        $this->variable = $variable;
29        $this->index = $index;
30        $this->currentFileInfo = $currentFileInfo;
31    }
32
33    public function accept( $visitor ) {
34    }
35
36    public function compile( $env ) {
37        $detachedRuleset = ( new Less_Tree_Variable( $this->variable, $this->index, $this->currentFileInfo ) )
38            ->compile( $env );
39
40        if ( !( $detachedRuleset instanceof Less_Tree_DetachedRuleset ) || !$detachedRuleset->ruleset ) {
41            // order differs from upstream to simplify the code
42            if ( is_array( $detachedRuleset ) ) {
43                $rules = new Less_Tree_Ruleset( null, $detachedRuleset );
44            } elseif (
45                ( $detachedRuleset instanceof Less_Tree_Ruleset
46                || $detachedRuleset instanceof Less_Tree_AtRule
47                || $detachedRuleset instanceof Less_Tree_Media
48                || $detachedRuleset instanceof Less_Tree_Mixin_Definition
49                ) && $detachedRuleset->rules
50            ) {
51                // @todo - note looks like dead code, do we need it ?
52                $rules = $detachedRuleset;
53            } elseif ( $detachedRuleset instanceof Less_Tree && is_array( $detachedRuleset->value ) ) {
54                $rules = new Less_Tree_Ruleset( null, $detachedRuleset->value );
55            } else {
56                throw new Less_Exception_Compiler( 'Could not evaluate variable call ' . $this->variable );
57            }
58            $detachedRuleset = new Less_Tree_DetachedRuleset( $rules );
59        }
60        if ( $detachedRuleset->ruleset ) {
61            return $detachedRuleset->callEval( $env );
62        }
63        throw new Less_Exception_Compiler( 'Could not evaluate variable call ' . $this->variable );
64    }
65}