aboutsummaryrefslogtreecommitdiff
path: root/lib/exTpl/BooleanExpression.php
blob: 0e18df02594dbaf4f80bf6b90cd4fae6f4e06e91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php

namespace exTpl;

/**
 * BooleanExpression represents a boolean operator.
 */
class BooleanExpression extends BinaryExpression
{
    /**
     * Returns the value of this expression.
     *
     * @param Context $context symbol table
     */
    public function value(Context $context): bool
    {
        $left  = $this->left->value($context);
        $right = $this->right->value($context);

        return match ($this->operator) {
            T_IS_EQUAL            => $left == $right,
            T_IS_NOT_EQUAL        => $left != $right,
            '<'                   => $left < $right,
            T_IS_SMALLER_OR_EQUAL => $left <= $right,
            '>'                   => $left > $right,
            T_IS_GREATER_OR_EQUAL => $left >= $right,
            T_BOOLEAN_AND         => $left && $right,
            T_BOOLEAN_OR          => $left || $right,
        };
    }
}