Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
90.57% |
48 / 53 |
|
72.73% |
8 / 11 |
CRAP | |
0.00% |
0 / 1 |
| Less_Tree_AtRule | |
90.57% |
48 / 53 |
|
72.73% |
8 / 11 |
26.57 | |
0.00% |
0 / 1 |
| __construct | |
92.86% |
13 / 14 |
|
0.00% |
0 / 1 |
4.01 | |||
| accept | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 | |||
| isRulesetLike | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| isCharset | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| genCSS | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
3 | |||
| compile | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
3 | |||
| variable | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| find | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| markReferenced | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| getIsReferenced | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
3 | |||
| emptySelectors | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @private |
| 4 | * @see less-3.13.1.js#AtRule.prototype |
| 5 | */ |
| 6 | class Less_Tree_AtRule extends Less_Tree implements Less_Tree_HasValueProperty { |
| 7 | /** @var string */ |
| 8 | public $name; |
| 9 | /** @var Less_Tree|null */ |
| 10 | public $value; |
| 11 | /** @var Less_Tree_Ruleset[]|null */ |
| 12 | public $rules; |
| 13 | /** @var int|null */ |
| 14 | public $index; |
| 15 | /** @var bool */ |
| 16 | public $isReferenced; |
| 17 | /** @var bool */ |
| 18 | public $isRooted; |
| 19 | /** @var array|null */ |
| 20 | public $currentFileInfo; |
| 21 | /** @var mixed|null */ |
| 22 | public $debugInfo; |
| 23 | |
| 24 | public function __construct( |
| 25 | $name, |
| 26 | $value = null, |
| 27 | $rules = null, |
| 28 | $index = null, |
| 29 | $isRooted = false, |
| 30 | $currentFileInfo = null, |
| 31 | $debugInfo = null, |
| 32 | $isReferenced = false |
| 33 | ) { |
| 34 | $this->name = $name; |
| 35 | // TODO: Less.js 3.13 handles `$value instanceof Less_Tree` and creates Anonymous here. |
| 36 | $this->value = $value; |
| 37 | |
| 38 | if ( $rules !== null ) { |
| 39 | if ( is_array( $rules ) ) { |
| 40 | $this->rules = $rules; |
| 41 | } else { |
| 42 | $this->rules = [ $rules ]; |
| 43 | $this->rules[0]->selectors = $this->emptySelectors(); |
| 44 | } |
| 45 | |
| 46 | foreach ( $this->rules as $rule ) { |
| 47 | $rule->allowImports = true; |
| 48 | } |
| 49 | // TODO: Less.js 3.13 handles setParent() here |
| 50 | } |
| 51 | |
| 52 | $this->index = $index; |
| 53 | $this->isRooted = $isRooted; |
| 54 | $this->currentFileInfo = $currentFileInfo; |
| 55 | $this->debugInfo = $debugInfo; |
| 56 | $this->isReferenced = $isReferenced; |
| 57 | } |
| 58 | |
| 59 | public function accept( $visitor ) { |
| 60 | if ( $this->rules ) { |
| 61 | $this->rules = $visitor->visitArray( $this->rules ); |
| 62 | } |
| 63 | if ( $this->value ) { |
| 64 | $this->value = $visitor->visitObj( $this->value ); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | public function isRulesetLike() { |
| 69 | return $this->rules || !$this->isCharset(); |
| 70 | } |
| 71 | |
| 72 | public function isCharset() { |
| 73 | return $this->name === "@charset"; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * @see Less_Tree::genCSS |
| 78 | */ |
| 79 | public function genCSS( $output ) { |
| 80 | $output->add( $this->name, $this->currentFileInfo, $this->index ); |
| 81 | if ( $this->value ) { |
| 82 | $output->add( ' ' ); |
| 83 | $this->value->genCSS( $output ); |
| 84 | } |
| 85 | if ( $this->rules !== null ) { |
| 86 | Less_Tree::outputRuleset( $output, $this->rules ); |
| 87 | } else { |
| 88 | $output->add( ';' ); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | public function compile( $env ) { |
| 93 | $value = $this->value; |
| 94 | $rules = $this->rules; |
| 95 | |
| 96 | // Media stored inside other directive should not bubble over it |
| 97 | // backup media bubbling information |
| 98 | $mediaPathBackup = $env->mediaPath; |
| 99 | $mediaPBlocksBackup = $env->mediaBlocks; |
| 100 | // Deleted media bubbling information |
| 101 | $env->mediaPath = []; |
| 102 | $env->mediaBlocks = []; |
| 103 | |
| 104 | if ( $value ) { |
| 105 | $value = $value->compile( $env ); |
| 106 | } |
| 107 | |
| 108 | if ( $rules ) { |
| 109 | // Assuming that there is only one rule at this point - that is how parser constructs the rule |
| 110 | $rules = $rules[0]->compile( $env ); |
| 111 | $rules->root = true; |
| 112 | } |
| 113 | |
| 114 | // Restore media bubbling information |
| 115 | $env->mediaPath = $mediaPathBackup; |
| 116 | $env->mediaBlocks = $mediaPBlocksBackup; |
| 117 | |
| 118 | return new self( $this->name, $value, $rules, $this->index, $this->isRooted, $this->currentFileInfo, $this->debugInfo, $this->isReferenced ); |
| 119 | } |
| 120 | |
| 121 | public function variable( $name ) { |
| 122 | if ( $this->rules ) { |
| 123 | return $this->rules[0]->variable( $name ); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | public function find( $selector ) { |
| 128 | // TODO: Less.js 3.13.1 adds multiple variadic arguments here |
| 129 | if ( $this->rules ) { |
| 130 | return $this->rules[0]->find( $selector, $this ); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | // TODO: Implement less-3.13.1.js#AtRule.prototype.rulesets |
| 135 | // Unused? |
| 136 | |
| 137 | // TODO: Implement less-3.13.1.js#AtRule.prototype.outputRuleset |
| 138 | // We have ours in Less_Tree::outputRuleset instead. |
| 139 | |
| 140 | public function markReferenced() { |
| 141 | $this->isReferenced = true; |
| 142 | if ( $this->rules ) { |
| 143 | Less_Tree::ReferencedArray( $this->rules ); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | public function getIsReferenced() { |
| 148 | return !isset( $this->currentFileInfo['reference'] ) || !$this->currentFileInfo['reference'] || $this->isReferenced; |
| 149 | } |
| 150 | |
| 151 | public function emptySelectors() { |
| 152 | $el = new Less_Tree_Element( '', '&', $this->index, $this->currentFileInfo ); |
| 153 | $sels = [ new Less_Tree_Selector( [ $el ], [], null, $this->index, $this->currentFileInfo ) ]; |
| 154 | $sels[0]->mediaEmpty = true; |
| 155 | return $sels; |
| 156 | } |
| 157 | |
| 158 | } |