Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
70.18% |
40 / 57 |
|
77.78% |
7 / 9 |
CRAP | |
0.00% |
0 / 1 |
Less_Tree | |
70.18% |
40 / 57 |
|
77.78% |
7 / 9 |
64.67 | |
0.00% |
0 / 1 |
toCSS | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
genCSS | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
compile | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
outputRuleset | |
100.00% |
17 / 17 |
|
100.00% |
1 / 1 |
4 | |||
accept | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
nodeCompare | |
36.84% |
7 / 19 |
|
0.00% |
0 / 1 |
89.81 | |||
numericCompare | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
4 | |||
ReferencedArray | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
3 | |||
__set_state | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | /** |
4 | * Tree |
5 | */ |
6 | class Less_Tree { |
7 | |
8 | public $parensInOp = false; |
9 | public $extendOnEveryPath; |
10 | public $allExtends; |
11 | |
12 | /** |
13 | * @see less-2.5.3.js#Node.prototype.toCSS |
14 | */ |
15 | public function toCSS() { |
16 | $output = new Less_Output(); |
17 | $this->genCSS( $output ); |
18 | return $output->toString(); |
19 | } |
20 | |
21 | /** |
22 | * Generate CSS by adding it to the output object |
23 | * |
24 | * @param Less_Output $output The output |
25 | * @return void |
26 | */ |
27 | public function genCSS( $output ) { |
28 | } |
29 | |
30 | public function compile( $env ) { |
31 | return $this; |
32 | } |
33 | |
34 | /** |
35 | * @param Less_Output $output |
36 | * @param Less_Tree_Ruleset[] $rules |
37 | */ |
38 | public static function outputRuleset( $output, $rules ) { |
39 | $ruleCnt = count( $rules ); |
40 | Less_Environment::$tabLevel++; |
41 | |
42 | // Compressed |
43 | if ( Less_Parser::$options['compress'] ) { |
44 | $output->add( '{' ); |
45 | for ( $i = 0; $i < $ruleCnt; $i++ ) { |
46 | $rules[$i]->genCSS( $output ); |
47 | } |
48 | |
49 | $output->add( '}' ); |
50 | Less_Environment::$tabLevel--; |
51 | return; |
52 | } |
53 | |
54 | // Non-compressed |
55 | $tabSetStr = "\n" . str_repeat( Less_Parser::$options['indentation'], Less_Environment::$tabLevel - 1 ); |
56 | $tabRuleStr = $tabSetStr . Less_Parser::$options['indentation']; |
57 | |
58 | $output->add( " {" ); |
59 | for ( $i = 0; $i < $ruleCnt; $i++ ) { |
60 | $output->add( $tabRuleStr ); |
61 | $rules[$i]->genCSS( $output ); |
62 | } |
63 | Less_Environment::$tabLevel--; |
64 | $output->add( $tabSetStr . '}' ); |
65 | } |
66 | |
67 | public function accept( $visitor ) { |
68 | } |
69 | |
70 | /** |
71 | * @param Less_Tree $a |
72 | * @param Less_Tree $b |
73 | * @return int|null |
74 | * @see less-2.5.3.js#Node.compare |
75 | */ |
76 | public static function nodeCompare( $a, $b ) { |
77 | // Less_Tree subclasses that implement compare() are: |
78 | // Anonymous, Color, Dimension, Keyword, Quoted, Unit |
79 | if ( $b instanceof Less_Tree_Quoted || $b instanceof Less_Tree_Anonymous ) { |
80 | // for "symmetric results" force toCSS-based comparison via b.compare() |
81 | // of Quoted or Anonymous if either value is one of those |
82 | // In JS, `-undefined` produces NAN, which, just like undefined |
83 | // will enter the the default/false branch of Less_Tree_Condition#compile. |
84 | // In PHP, `-null` is 0. To ensure parity, preserve the null. |
85 | $res = $b->compare( $a ); |
86 | return $res !== null ? -$res : null; |
87 | } elseif ( $a instanceof Less_Tree_Anonymous || $a instanceof Less_Tree_Color |
88 | || $a instanceof Less_Tree_Dimension || $a instanceof Less_Tree_Keyword |
89 | || $a instanceof Less_Tree_Quoted || $a instanceof Less_Tree_Unit |
90 | ) { |
91 | return $a->compare( $b ); |
92 | } elseif ( get_class( $a ) !== get_class( $b ) ) { |
93 | return null; |
94 | } |
95 | |
96 | // Less_Tree subclasses that have an array value: Less_Tree_Expression, Less_Tree_Value |
97 | // @phan-suppress-next-line PhanUndeclaredProperty |
98 | $aval = $a->value ?? []; |
99 | // @phan-suppress-next-line PhanUndeclaredProperty |
100 | $bval = $b->value ?? []; |
101 | if ( !( $a instanceof Less_Tree_Expression || $a instanceof Less_Tree_Value ) ) { |
102 | return $aval === $bval ? 0 : null; |
103 | } |
104 | if ( count( $aval ) !== count( $bval ) ) { |
105 | return null; |
106 | } |
107 | foreach ( $aval as $i => $item ) { |
108 | if ( self::nodeCompare( $item, $bval[$i] ) !== 0 ) { |
109 | return null; |
110 | } |
111 | } |
112 | return 0; |
113 | } |
114 | |
115 | /** |
116 | * @param string|float|int $a |
117 | * @param string|float|int $b |
118 | * @return int|null |
119 | * @see less-2.5.3.js#Node.numericCompare |
120 | */ |
121 | public static function numericCompare( $a, $b ) { |
122 | return $a < $b ? -1 |
123 | : ( $a === $b ? 0 |
124 | : ( $a > $b ? 1 |
125 | // NAN is not greater, less, or equal |
126 | : null |
127 | ) |
128 | ); |
129 | } |
130 | |
131 | public static function ReferencedArray( $rules ) { |
132 | foreach ( $rules as $rule ) { |
133 | if ( method_exists( $rule, 'markReferenced' ) ) { |
134 | // @phan-suppress-next-line PhanUndeclaredMethod |
135 | $rule->markReferenced(); |
136 | } |
137 | } |
138 | } |
139 | |
140 | /** |
141 | * Requires php 5.3+ |
142 | */ |
143 | public static function __set_state( $args ) { |
144 | $class = get_called_class(); |
145 | $obj = new $class( null, null, null, null ); |
146 | foreach ( $args as $key => $val ) { |
147 | $obj->$key = $val; |
148 | } |
149 | return $obj; |
150 | } |
151 | |
152 | } |