Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
96.15% covered (success)
96.15%
25 / 26
85.71% covered (warning)
85.71%
6 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
Less_Visitor_joinSelector
96.15% covered (success)
96.15%
25 / 26
85.71% covered (warning)
85.71%
6 / 7
20
0.00% covered (danger)
0.00%
0 / 1
 run
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 visitDeclration
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 visitMixinDefinition
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 visitRuleset
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
8
 visitRulesetOut
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 visitMedia
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
4
 visitAtRule
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2/**
3 * @private
4 */
5class Less_Visitor_joinSelector extends Less_Visitor {
6
7    public $contexts = [ [] ];
8
9    /**
10     * @param Less_Tree_Ruleset $root
11     */
12    public function run( $root ) {
13        return $this->visitObj( $root );
14    }
15
16    public function visitDeclration( $declNode, &$visitDeeper ) {
17        $visitDeeper = false;
18    }
19
20    public function visitMixinDefinition( $mixinDefinitionNode, &$visitDeeper ) {
21        $visitDeeper = false;
22    }
23
24    public function visitRuleset( $rulesetNode ) {
25        $context = end( $this->contexts );
26        $paths = [];
27
28        if ( !$rulesetNode->root ) {
29            $selectors = $rulesetNode->selectors;
30            if ( $selectors !== null ) {
31                $filtered = [];
32                foreach ( $selectors as $selector ) {
33                    if ( $selector->getIsOutput() ) {
34                        $filtered[] = $selector;
35                    }
36                }
37                $selectors = $rulesetNode->selectors = $filtered ?: null;
38                if ( $selectors ) {
39                    $paths = $rulesetNode->joinSelectors( $context, $selectors );
40                }
41            }
42
43            if ( $selectors === null ) {
44                $rulesetNode->rules = null;
45            }
46
47            $rulesetNode->paths = $paths;
48        }
49
50        // NOTE: Assigned here instead of at the start like less.js,
51        // because PHP arrays aren't by-ref
52        $this->contexts[] = $paths;
53    }
54
55    public function visitRulesetOut() {
56        array_pop( $this->contexts );
57    }
58
59    public function visitMedia( $mediaNode ) {
60        $context = end( $this->contexts );
61
62        if ( count( $context ) === 0 || ( is_object( $context[0] ) && $context[0]->multiMedia ) ) {
63            $mediaNode->rules[0]->root = true;
64        }
65    }
66
67    public function visitAtRule( $atRuleNode ) {
68        $context = end( $this->contexts );
69
70        if ( $atRuleNode->rules && count( $atRuleNode->rules ) > 0 ) {
71            $atRuleNode->rules[0]->root = $atRuleNode->isRooted || count( $context ) === 0;
72        }
73    }
74
75}