Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
88.24% |
30 / 34 |
|
80.00% |
4 / 5 |
CRAP | |
0.00% |
0 / 1 |
Less_Tree_Quoted | |
88.24% |
30 / 34 |
|
80.00% |
4 / 5 |
18.53 | |
0.00% |
0 / 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 | |||
compile | |
75.00% |
12 / 16 |
|
0.00% |
0 / 1 |
6.56 | |||
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 | /** |
14 | * @param string $str |
15 | */ |
16 | public function __construct( $str, $content = '', $escaped = true, $index = false, $currentFileInfo = null ) { |
17 | $this->escaped = $escaped; |
18 | $this->value = $content; |
19 | if ( $str ) { |
20 | $this->quote = $str[0]; |
21 | } |
22 | $this->index = $index; |
23 | $this->currentFileInfo = $currentFileInfo; |
24 | } |
25 | |
26 | /** |
27 | * @see Less_Tree::genCSS |
28 | */ |
29 | public function genCSS( $output ) { |
30 | if ( !$this->escaped ) { |
31 | $output->add( $this->quote, $this->currentFileInfo, $this->index ); |
32 | } |
33 | $output->add( $this->value ); |
34 | if ( !$this->escaped ) { |
35 | $output->add( $this->quote ); |
36 | } |
37 | } |
38 | |
39 | public function containsVariables() { |
40 | return preg_match( '/(`([^`]+)`)|@\{([\w-]+)\}/', $this->value ); |
41 | } |
42 | |
43 | public function compile( $env ) { |
44 | $value = $this->value; |
45 | if ( preg_match_all( '/`([^`]+)`/', $this->value, $matches ) ) { |
46 | foreach ( $matches[1] as $i => $match ) { |
47 | $js = new Less_Tree_JavaScript( $match, $this->index, true ); |
48 | $js = $js->compile( $env )->value; |
49 | $value = str_replace( $matches[0][$i], $js, $value ); |
50 | } |
51 | } |
52 | $r = $value; |
53 | do { |
54 | $value = $r; |
55 | if ( preg_match_all( '/@\{([\w-]+)\}/', $value, $matches ) ) { |
56 | foreach ( $matches[1] as $i => $match ) { |
57 | $v = new Less_Tree_Variable( '@' . $match, $this->index, $this->currentFileInfo ); |
58 | $v = $v->compile( $env ); |
59 | $v = ( $v instanceof self ) ? $v->value : $v->toCSS(); |
60 | $r = str_replace( $matches[0][$i], $v, $r ); |
61 | } |
62 | } |
63 | } while ( $r != $value ); |
64 | |
65 | return new self( $this->quote . $r . $this->quote, $r, $this->escaped, $this->index, $this->currentFileInfo ); |
66 | } |
67 | |
68 | /** |
69 | * @param mixed $other |
70 | * @return int|null |
71 | * @see less-2.5.3.js#Quoted.prototype.compare |
72 | */ |
73 | public function compare( $other ) { |
74 | if ( $other instanceof self && !$this->escaped && !$other->escaped ) { |
75 | return Less_Tree::numericCompare( $this->value, $other->value ); |
76 | } else { |
77 | return ( |
78 | Less_Parser::is_method( $other, 'toCSS' ) |
79 | && $this->toCSS() === $other->toCSS() |
80 | ) ? 0 : null; |
81 | } |
82 | } |
83 | } |