Completed
Pull Request — master (#354)
by Strahinja
04:13
created

NotEqual   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 6
cts 7
cp 0.8571
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A compile() 0 14 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 NotEqual extends AbstractExpressionCompiler
16
{
17
    protected $name = 'PhpParser\Node\Expr\BinaryOp\NotEqual';
18
19
    /**
20
     * It's used in conditions
21
     * {left-expr} != {right-expr}
22
     *
23
     * @param \PhpParser\Node\Expr\BinaryOp\NotEqual $expr
24
     * @param Context $context
25
     * @return CompiledExpression
26
     */
27 2
    protected function compile($expr, Context $context)
28
    {
29 2
        $left = $context->getExpressionCompiler()->compile($expr->left);
30 2
        $right = $context->getExpressionCompiler()->compile($expr->right);
31
32 2
        if ($left->isTypeKnown() && $right->isTypeKnown()) {
33 2
            return CompiledExpression::fromZvalValue(
34 2
                $left->getValue() != $right->getValue()
35
            );
36
        }
37
38
39
        return new CompiledExpression();
40
    }
41
}
42