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

Equal::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
 * PHP Smart Analysis project 2015-2016
4
 *
5
 * @author Patsura Dmitry https://github.com/ovr <[email protected]>
6
 */
7
8
namespace PHPSA\Compiler\Expression\BinaryOp;
9
10
use PHPSA\CompiledExpression;
11
use PHPSA\Context;
12
use PHPSA\Compiler\Expression;
13
use PHPSA\Compiler\Expression\AbstractExpressionCompiler;
14
15
class Equal extends AbstractExpressionCompiler
16
{
17
    protected $name = 'PhpParser\Node\Expr\BinaryOp\Equal';
18
19
    /**
20
     * {left-expr} == {right-expr}
21
     *
22
     * @param \PhpParser\Node\Expr\BinaryOp\Equal $expr
23
     * @param Context $context
24
     * @return CompiledExpression
25
     */
26 1
    protected function compile($expr, Context $context)
27
    {
28 1
        $left = $context->getExpressionCompiler()->compile($expr->left);
29 1
        $right = $context->getExpressionCompiler()->compile($expr->right);
30
31 1
        if ($left->isTypeKnown() && $right->isTypeKnown()) {
32 1
            return CompiledExpression::fromZvalValue(
33 1
                $left->getValue() == $right->getValue()
34 1
            );
35
        }
36
37
        return new CompiledExpression();
38
    }
39
}
40