Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
40 / 40 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
Less_Tree_Quoted | |
100.00% |
40 / 40 |
|
100.00% |
7 / 7 |
21 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
genCSS | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
containsVariables | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
variableReplacement | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
4 | |||
propertyReplacement | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
4 | |||
compile | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
compare | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
6 |
1 | <?php |
2 | /** |
3 | * @private |
4 | */ |
5 | class Less_Tree_Quoted extends Less_Tree implements Less_Tree_HasValueProperty { |
6 | public $escaped; |
7 | /** @var string */ |
8 | public $value; |
9 | public $quote; |
10 | public $index; |
11 | public $currentFileInfo; |
12 | |
13 | public $variableRegex = '/@\{([\w-]+)\}/'; |
14 | public $propRegex = '/\$\{([\w-]+)\}/'; |
15 | |
16 | /** |
17 | * @param string $str |
18 | */ |
19 | public function __construct( $str, $content = '', $escaped = true, $index = false, $currentFileInfo = null ) { |
20 | $this->escaped = $escaped; |
21 | $this->value = $content; |
22 | if ( $str ) { |
23 | $this->quote = $str[0]; |
24 | } |
25 | $this->index = $index; |
26 | $this->currentFileInfo = $currentFileInfo; |
27 | } |
28 | |
29 | /** |
30 | * @see Less_Tree::genCSS |
31 | */ |
32 | public function genCSS( $output ) { |
33 | if ( !$this->escaped ) { |
34 | $output->add( $this->quote, $this->currentFileInfo, $this->index ); |
35 | } |
36 | $output->add( $this->value ); |
37 | if ( !$this->escaped ) { |
38 | $output->add( $this->quote ); |
39 | } |
40 | } |
41 | |
42 | /** |
43 | * @see less-3.13.1.js#Quoted.prototype.containsVariables |
44 | */ |
45 | public function containsVariables() { |
46 | return preg_match( $this->variableRegex, $this->value ); |
47 | } |
48 | |
49 | private function variableReplacement( $r, $env ) { |
50 | do { |
51 | $value = $r; |
52 | if ( preg_match_all( $this->variableRegex, $value, $matches ) ) { |
53 | foreach ( $matches[1] as $i => $match ) { |
54 | $v = new Less_Tree_Variable( '@' . $match, $this->index, $this->currentFileInfo ); |
55 | $v = $v->compile( $env ); |
56 | $v = ( $v instanceof self ) ? $v->value : $v->toCSS(); |
57 | $r = str_replace( $matches[0][$i], $v, $r ); |
58 | } |
59 | } |
60 | } while ( $r != $value ); |
61 | return $r; |
62 | } |
63 | |
64 | private function propertyReplacement( $r, $env ) { |
65 | do { |
66 | $value = $r; |
67 | if ( preg_match_all( $this->propRegex, $value, $matches ) ) { |
68 | foreach ( $matches[1] as $i => $match ) { |
69 | $v = new Less_Tree_Property( '$' . $match, $this->index, $this->currentFileInfo ); |
70 | $v = $v->compile( $env ); |
71 | $v = ( $v instanceof self ) ? $v->value : $v->toCSS(); |
72 | $r = str_replace( $matches[0][$i], $v, $r ); |
73 | } |
74 | } |
75 | } while ( $r != $value ); |
76 | return $r; |
77 | } |
78 | |
79 | public function compile( $env ) { |
80 | $value = $this->value; |
81 | $value = $this->variableReplacement( $value, $env ); |
82 | $value = $this->propertyReplacement( $value, $env ); |
83 | return new self( $this->quote . $value . $this->quote, $value, $this->escaped, $this->index, $this->currentFileInfo ); |
84 | } |
85 | |
86 | /** |
87 | * @param mixed $other |
88 | * @return int|null |
89 | * @see less-2.5.3.js#Quoted.prototype.compare |
90 | */ |
91 | public function compare( $other ) { |
92 | if ( $other instanceof self && !$this->escaped && !$other->escaped ) { |
93 | return Less_Tree::numericCompare( $this->value, $other->value ); |
94 | } else { |
95 | return ( |
96 | Less_Parser::is_method( $other, 'toCSS' ) |
97 | && $this->toCSS() === $other->toCSS() |
98 | ) ? 0 : null; |
99 | } |
100 | } |
101 | } |