AbstractOperator::compile()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
nc 2
nop 2
dl 0
loc 13
ccs 0
cts 7
cp 0
crap 12
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
namespace PHPSA\Compiler\Expression\Operators\Comparison;
4
5
use PHPSA\CompiledExpression;
6
use PHPSA\Context;
7
use PHPSA\Compiler\Expression;
8
use PHPSA\Compiler\Expression\AbstractExpressionCompiler;
9
10
abstract class AbstractOperator extends AbstractExpressionCompiler
11
{
12
    /**
13
     * Do compare
14
     *
15
     * @param $left
16
     * @param $right
17
     * @return boolean
18
     */
19
    abstract public function compare($left, $right);
20
21
    /**
22
     * {expr} $operator {expr}
23
     *
24
     * @param \PhpParser\Node\Expr\BinaryOp $expr
25
     * @param Context $context
26
     * @return CompiledExpression
27
     */
28
    protected function compile($expr, Context $context)
29
    {
30
        $left = $context->getExpressionCompiler()->compile($expr->left);
31
        $right = $context->getExpressionCompiler()->compile($expr->right);
32
33
        if ($left->isTypeKnown() && $right->isTypeKnown()) {
34
            return CompiledExpression::fromZvalValue(
35
                $this->compare($left->getValue(), $right->getValue())
36
            );
37
        }
38
39
        return new CompiledExpression();
40
    }
41
}
42