Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
25 / 25 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
Less_Tree_Operation | |
100.00% |
25 / 25 |
|
100.00% |
4 / 4 |
17 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
accept | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
compile | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
12 | |||
genCSS | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | /** |
3 | * @private |
4 | * @see less-3.13.1.js#Operation.prototype |
5 | */ |
6 | class Less_Tree_Operation extends Less_Tree { |
7 | |
8 | public $op; |
9 | public $operands; |
10 | public $isSpaced; |
11 | |
12 | /** |
13 | * @param string $op |
14 | */ |
15 | public function __construct( $op, $operands, $isSpaced = false ) { |
16 | $this->op = trim( $op ); |
17 | $this->operands = $operands; |
18 | $this->isSpaced = $isSpaced; |
19 | } |
20 | |
21 | public function accept( $visitor ) { |
22 | $this->operands = $visitor->visitArray( $this->operands ); |
23 | } |
24 | |
25 | public function compile( $env ) { |
26 | $a = $this->operands[0]->compile( $env ); |
27 | $b = $this->operands[1]->compile( $env ); |
28 | |
29 | // Skip operation if argument was not compiled down to a non-operable value. |
30 | // For example, if one argument is a Less_Tree_Call like 'var(--foo)' then we |
31 | // preserve it as literal for native CSS. |
32 | // https://phabricator.wikimedia.org/T331688 |
33 | if ( $env->isMathOn( $this->op ) ) { |
34 | $op = $this->op === './' ? '/' : $this->op; |
35 | |
36 | if ( $a instanceof Less_Tree_Dimension && $b instanceof Less_Tree_Color ) { |
37 | $a = $a->toColor(); |
38 | } elseif ( $b instanceof Less_Tree_Dimension && $a instanceof Less_Tree_Color ) { |
39 | $b = $b->toColor(); |
40 | } |
41 | |
42 | if ( !( $a instanceof Less_Tree_Dimension || $a instanceof Less_Tree_Color ) ) { |
43 | if ( $a instanceof Less_Tree_Operation && $a->op === '/' && $env->math === Less_Environment::MATH_PARENS_DIVISION |
44 | ) { |
45 | return new self( $this->op, [ $a, $b ], $this->isSpaced ); |
46 | } |
47 | throw new Less_Exception_Compiler( "Operation on an invalid type" ); |
48 | } |
49 | |
50 | return $a->operate( $op, $b ); |
51 | } else { |
52 | return new self( $this->op, [ $a, $b ], $this->isSpaced ); |
53 | } |
54 | } |
55 | |
56 | /** |
57 | * @see Less_Tree::genCSS |
58 | */ |
59 | public function genCSS( $output ) { |
60 | $this->operands[0]->genCSS( $output ); |
61 | if ( $this->isSpaced ) { |
62 | $output->add( " " ); |
63 | } |
64 | $output->add( $this->op ); |
65 | if ( $this->isSpaced ) { |
66 | $output->add( ' ' ); |
67 | } |
68 | $this->operands[1]->genCSS( $output ); |
69 | } |
70 | |
71 | } |