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