Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
93.33% |
14 / 15 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
| Less_Tree_Attribute | |
93.33% |
14 / 15 |
|
75.00% |
3 / 4 |
10.03 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| compile | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
5 | |||
| genCSS | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| toCSS | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @private |
| 4 | * @see less-2.5.3.js#Attribute.prototype |
| 5 | */ |
| 6 | class Less_Tree_Attribute extends Less_Tree implements Less_Tree_HasValueProperty { |
| 7 | /** @var string */ |
| 8 | public $key; |
| 9 | /** @var null|string */ |
| 10 | public $op; |
| 11 | /** @var null|string|Less_Tree */ |
| 12 | public $value; |
| 13 | |
| 14 | /** |
| 15 | * @param string $key |
| 16 | * @param null|string $op |
| 17 | * @param null|string|Less_Tree $value |
| 18 | */ |
| 19 | public function __construct( $key, $op, $value ) { |
| 20 | $this->key = $key; |
| 21 | $this->op = $op; |
| 22 | $this->value = $value; |
| 23 | } |
| 24 | |
| 25 | public function compile( $env ) { |
| 26 | // Optimization: Avoid object churn for the common case. |
| 27 | // Attributes are very common in CSS/LESS input, but rarely involve dynamic values. |
| 28 | if ( !$this->key instanceof Less_Tree && !$this->value instanceof Less_Tree ) { |
| 29 | return $this; |
| 30 | } |
| 31 | |
| 32 | return new self( |
| 33 | $this->key instanceof Less_Tree ? $this->key->compile( $env ) : $this->key, |
| 34 | $this->op, |
| 35 | $this->value instanceof Less_Tree ? $this->value->compile( $env ) : $this->value ); |
| 36 | } |
| 37 | |
| 38 | public function genCSS( $output ) { |
| 39 | $output->add( $this->toCSS() ); |
| 40 | } |
| 41 | |
| 42 | public function toCSS() { |
| 43 | $value = $this->key; |
| 44 | |
| 45 | if ( $this->op ) { |
| 46 | $value .= $this->op; |
| 47 | $value .= ( $this->value instanceof Less_Tree ? $this->value->toCSS() : $this->value ); |
| 48 | } |
| 49 | |
| 50 | return '[' . $value . ']'; |
| 51 | } |
| 52 | } |