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

Equal   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 7
cts 8
cp 0.875
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A compile() 0 13 3
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