Completed
Push — master ( 69939e...ded049 )
by Enrico
02:49
created

AbstractOperator::compile()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3.0175

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 2
nop 2
dl 0
loc 13
ccs 7
cts 8
cp 0.875
crap 3.0175
rs 9.4285
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 1
    protected function compile($expr, Context $context)
29
    {
30 1
        $left = $context->getExpressionCompiler()->compile($expr->left);
31 1
        $right = $context->getExpressionCompiler()->compile($expr->right);
32
33 1
        if ($left->isTypeKnown() && $right->isTypeKnown()) {
34 1
            return CompiledExpression::fromZvalValue(
35 1
                $this->compare($left->getValue(), $right->getValue())
36 1
            );
37
        }
38
39
        return new CompiledExpression();
40
    }
41
}
42