Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
25 / 25
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
Less_Tree_Condition
100.00% covered (success)
100.00%
25 / 25
100.00% covered (success)
100.00%
3 / 3
18
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 accept
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 compile
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
1 / 1
16
1<?php
2/**
3 * @private
4 */
5class Less_Tree_Condition extends Less_Tree {
6
7    public $op;
8    public $lvalue;
9    public $rvalue;
10    public $index;
11    public $negate;
12
13    public function __construct( $op, $l, $r, $i = 0, $negate = false ) {
14        $this->op = trim( $op );
15        $this->lvalue = $l;
16        $this->rvalue = $r;
17        $this->index = $i;
18        $this->negate = $negate;
19    }
20
21    public function accept( $visitor ) {
22        $this->lvalue = $visitor->visitObj( $this->lvalue );
23        $this->rvalue = $visitor->visitObj( $this->rvalue );
24    }
25
26    /**
27     * @param Less_Environment $env
28     * @return bool
29     * @see less-2.5.3.js#Condition.prototype.eval
30     */
31    public function compile( $env ) {
32        $a = $this->lvalue->compile( $env );
33        $b = $this->rvalue->compile( $env );
34
35        switch ( $this->op ) {
36            case 'and':
37                $result = $a && $b;
38                break;
39
40            case 'or':
41                $result = $a || $b;
42                break;
43
44            default:
45                $res = Less_Tree::nodeCompare( $a, $b );
46                // In JS, switch(undefined) with -1,0,-1,defaults goes to `default`.
47                // In PHP, switch(null) would go to case 0. Use if/else instead.
48                if ( $res === -1 ) {
49                    $result = $this->op === '<' || $this->op === '=<' || $this->op === '<=';
50                } elseif ( $res === 0 ) {
51                    $result = $this->op === '=' || $this->op === '>=' || $this->op === '=<' || $this->op === '<=';
52                } elseif ( $res === 1 ) {
53                    $result = $this->op === '>' || $this->op === '>=';
54                } else {
55                    // null, NAN
56                    $result = false;
57                }
58        }
59
60        return $this->negate ? !$result : $result;
61    }
62
63}