Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
22 / 22 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
Less_Tree_Element | |
100.00% |
22 / 22 |
|
100.00% |
5 / 5 |
12 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
accept | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
compile | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
genCSS | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
toCSS | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
5 |
1 | <?php |
2 | /** |
3 | * @private |
4 | */ |
5 | class Less_Tree_Element extends Less_Tree implements Less_Tree_HasValueProperty { |
6 | |
7 | /** @var string */ |
8 | public $combinator; |
9 | /** @var bool Whether combinator is null (represented by empty string) or child (single space) */ |
10 | public $combinatorIsEmptyOrWhitespace; |
11 | /** @var string|Less_Tree */ |
12 | public $value; |
13 | public $index; |
14 | public $currentFileInfo; |
15 | |
16 | public $value_is_object = false; |
17 | |
18 | /** |
19 | * @param null|string $combinator |
20 | * @param string|Less_Tree $value |
21 | * @param int|null $index |
22 | * @param array|null $currentFileInfo |
23 | */ |
24 | public function __construct( $combinator, $value, $index = null, $currentFileInfo = null ) { |
25 | $this->value = $value; |
26 | $this->value_is_object = is_object( $value ); |
27 | |
28 | // see less-2.5.3.js#Combinator |
29 | $this->combinator = $combinator ?? ''; |
30 | $this->combinatorIsEmptyOrWhitespace = ( $combinator === null || trim( $combinator ) === '' ); |
31 | |
32 | $this->index = $index; |
33 | $this->currentFileInfo = $currentFileInfo; |
34 | } |
35 | |
36 | public function accept( $visitor ) { |
37 | if ( $this->value_is_object ) { // object or string |
38 | $this->value = $visitor->visitObj( $this->value ); |
39 | } |
40 | } |
41 | |
42 | public function compile( $env ) { |
43 | return new self( |
44 | $this->combinator, |
45 | ( $this->value_is_object ? $this->value->compile( $env ) : $this->value ), |
46 | $this->index, |
47 | $this->currentFileInfo |
48 | ); |
49 | } |
50 | |
51 | /** |
52 | * @see Less_Tree::genCSS |
53 | */ |
54 | public function genCSS( $output ) { |
55 | $output->add( $this->toCSS(), $this->currentFileInfo, $this->index ); |
56 | } |
57 | |
58 | public function toCSS() { |
59 | if ( $this->value_is_object ) { |
60 | $value = $this->value->toCSS(); |
61 | } else { |
62 | $value = $this->value; |
63 | } |
64 | |
65 | $spaceOrEmpty = ' '; |
66 | if ( Less_Parser::$options['compress'] || ( isset( Less_Environment::$_noSpaceCombinators[$this->combinator] ) && Less_Environment::$_noSpaceCombinators[$this->combinator] ) ) { |
67 | $spaceOrEmpty = ''; |
68 | } |
69 | |
70 | return $spaceOrEmpty . $this->combinator . $spaceOrEmpty . $value; |
71 | } |
72 | |
73 | } |