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