Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
41 / 41 |
|
100.00% |
11 / 11 |
CRAP | |
100.00% |
1 / 1 |
Less_Visitor_extendFinder | |
100.00% |
41 / 41 |
|
100.00% |
11 / 11 |
21 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
run | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
visitDeclaration | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
visitMixinDefinition | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
visitRuleset | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
8 | |||
allExtendsStackPush | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
2 | |||
visitRulesetOut | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
3 | |||
visitMedia | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
visitMediaOut | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
visitAtRule | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
visitAtRuleOut | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | /** |
3 | * @private |
4 | */ |
5 | class Less_Visitor_extendFinder extends Less_Visitor { |
6 | |
7 | public $contexts = []; |
8 | public $allExtendsStack; |
9 | public $foundExtends; |
10 | |
11 | public function __construct() { |
12 | $this->contexts = []; |
13 | $this->allExtendsStack = [ [] ]; |
14 | parent::__construct(); |
15 | } |
16 | |
17 | /** |
18 | * @param Less_Tree_Ruleset $root |
19 | */ |
20 | public function run( $root ) { |
21 | $root = $this->visitObj( $root ); |
22 | $root->allExtends =& $this->allExtendsStack[0]; |
23 | return $root; |
24 | } |
25 | |
26 | public function visitDeclaration( $declNode, &$visitDeeper ) { |
27 | $visitDeeper = false; |
28 | } |
29 | |
30 | public function visitMixinDefinition( $mixinDefinitionNode, &$visitDeeper ) { |
31 | $visitDeeper = false; |
32 | } |
33 | |
34 | public function visitRuleset( $rulesetNode ) { |
35 | if ( $rulesetNode->root ) { |
36 | return; |
37 | } |
38 | |
39 | $allSelectorsExtendList = []; |
40 | |
41 | // get &:extend(.a); rules which apply to all selectors in this ruleset |
42 | if ( $rulesetNode->rules ) { |
43 | foreach ( $rulesetNode->rules as $rule ) { |
44 | if ( $rule instanceof Less_Tree_Extend ) { |
45 | $allSelectorsExtendList[] = $rule; |
46 | $rulesetNode->extendOnEveryPath = true; |
47 | } |
48 | } |
49 | } |
50 | |
51 | // now find every selector and apply the extends that apply to all extends |
52 | // and the ones which apply to an individual extend |
53 | foreach ( $rulesetNode->paths as $selectorPath ) { |
54 | $selector = end( $selectorPath ); // $selectorPath[ count($selectorPath)-1]; |
55 | |
56 | $j = 0; |
57 | foreach ( $selector->extendList as $extend ) { |
58 | $this->allExtendsStackPush( $rulesetNode, $selectorPath, $extend, $j ); |
59 | } |
60 | foreach ( $allSelectorsExtendList as $extend ) { |
61 | $this->allExtendsStackPush( $rulesetNode, $selectorPath, $extend, $j ); |
62 | } |
63 | } |
64 | |
65 | $this->contexts[] = $rulesetNode->selectors; |
66 | } |
67 | |
68 | public function allExtendsStackPush( $rulesetNode, $selectorPath, Less_Tree_Extend $extend, &$j ) { |
69 | $this->foundExtends = true; |
70 | $extend = $extend->clone(); |
71 | $extend->findSelfSelectors( $selectorPath ); |
72 | $extend->ruleset = $rulesetNode; |
73 | if ( $j === 0 ) { |
74 | $extend->firstExtendOnThisSelectorPath = true; |
75 | } |
76 | |
77 | $end_key = count( $this->allExtendsStack ) - 1; |
78 | $this->allExtendsStack[$end_key][] = $extend; |
79 | $j++; |
80 | } |
81 | |
82 | public function visitRulesetOut( $rulesetNode ) { |
83 | if ( !is_object( $rulesetNode ) || !$rulesetNode->root ) { |
84 | array_pop( $this->contexts ); |
85 | } |
86 | } |
87 | |
88 | public function visitMedia( $mediaNode ) { |
89 | $mediaNode->allExtends = []; |
90 | $this->allExtendsStack[] =& $mediaNode->allExtends; |
91 | } |
92 | |
93 | public function visitMediaOut() { |
94 | array_pop( $this->allExtendsStack ); |
95 | } |
96 | |
97 | public function visitAtRule( $atRuleNode ) { |
98 | $atRuleNode->allExtends = []; |
99 | $this->allExtendsStack[] =& $atRuleNode->allExtends; |
100 | } |
101 | |
102 | public function visitAtRuleOut() { |
103 | array_pop( $this->allExtendsStack ); |
104 | } |
105 | } |