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