Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
46.51% covered (danger)
46.51%
20 / 43
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
Less_Tree_NamespaceValue
46.51% covered (danger)
46.51%
20 / 43
50.00% covered (danger)
50.00%
1 / 2
61.23
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 compile
41.03% covered (danger)
41.03%
16 / 39
0.00% covered (danger)
0.00%
0 / 1
68.51
1<?php
2/**
3 * @private
4 * @see less-3.13.1.js#NamespaceValue.prototype
5 */
6class Less_Tree_NamespaceValue extends Less_Tree {
7
8    /** @var Less_Tree_Mixin_Call|Less_Tree_VariableCall */
9    public $value;
10    public $index;
11    public $lookups;
12    public $currentFileInfo;
13
14    public function __construct( $ruleCall, $lookups, $index = null, $currentFileInfo = null ) {
15        $this->value = $ruleCall;
16        $this->lookups = $lookups;
17        $this->index = $index;
18        $this->currentFileInfo = $currentFileInfo;
19    }
20
21    public function compile( $env ) {
22        /** @var Less_Tree_Ruleset $rules */
23        $rules = $this->value->compile( $env );
24
25        foreach ( $this->lookups as $name ) {
26            /**
27             * Eval'd DRs return rulesets.
28             * Eval'd mixins return rules, so let's make a ruleset if we need it.
29             * We need to do this because of late parsing of values
30             */
31            if ( is_array( $rules ) ) {
32                $rules = new Less_Tree_Ruleset( [ new Less_Tree_Selector( [] ) ], $rules );
33            }
34            if ( $name === '' ) {
35                $rules = $rules->lastDeclaration();
36            } elseif ( $name[0] === '@' ) {
37                if ( ( $name[1] ?? '' ) === '@' ) {
38                    $variable = ( new Less_Tree_Variable( substr( $name, 1 ) ) )->compile( $env );
39                    $name = "@" . $variable->value;
40                }
41                if ( $rules instanceof Less_Tree_Ruleset ) {
42                    $rules = $rules->variable( $name );
43                }
44
45                if ( !$rules ) {
46                    throw new Less_Exception_Compiler(
47                        "Variable $name not found",
48                        null,
49                        $this->index,
50                        $this->currentFileInfo
51                    );
52                }
53            } else {
54                if ( strncmp( $name, '$@', 2 ) === 0 ) {
55                    $variable = ( new Less_Tree_Variable( substr( $name, 1 ) ) )->compile( $env );
56                    $name = "$" . $variable->value;
57                } else {
58                    $name = $name[0] === '$' ? $name : ( '$' . $name );
59                }
60
61                if ( $rules instanceof Less_Tree_Ruleset ) {
62                    $rules = $rules->property( $name );
63                }
64
65                if ( !$rules ) {
66                    throw new Less_Exception_Compiler(
67                        "Property $name not found",
68                        null,
69                        $this->index,
70                        $this->currentFileInfo
71                    );
72                }
73                // Properties are an array of values, since a ruleset can have multiple props.
74                // We pick the last one (the "cascaded" value)
75                if ( is_array( $rules ) ) { // to satisfy phan checks
76                    $rules = $rules[ count( $rules ) - 1 ];
77                }
78            }
79
80            if ( $rules->value ) {
81                $rules = $rules->compile( $env )->value;
82            }
83            if ( $rules instanceof Less_Tree_DetachedRuleset && $rules->ruleset ) {
84                // @todo - looks like this is never evaluated, investigate later
85                // @see https://github.com/less/less.js/commit/29468bffcd8a9f2f
86                $rules = $rules->ruleset->compile( $env );
87            }
88        }
89
90        return $rules;
91    }
92
93}