Completed
Pull Request — master (#341)
by Strahinja
04:06
created

BooleanNot   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 85.71%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A compile() 0 12 2
1
<?php
2
3
namespace PHPSA\Compiler\Expression\Operators\Logical;
4
5
use PHPSA\CompiledExpression;
6
use PHPSA\Context;
7
use PHPSA\Compiler\Expression;
8
use PHPSA\Compiler\Expression\AbstractExpressionCompiler;
9
10
class BooleanNot extends AbstractExpressionCompiler
11
{
12
    protected $name = 'PhpParser\Node\Expr\BooleanNot';
13
14
    /**
15
     * !{expr}
16
     *
17
     * @param \PhpParser\Node\Expr\BooleanNot $expr
18
     * @param Context $context
19
     * @return CompiledExpression
20
     */
21 2
    protected function compile($expr, Context $context)
22
    {
23 2
        $compiledExpression = $context->getExpressionCompiler()->compile($expr->expr);
24
25 2
        if ($compiledExpression->isTypeKnown()) {
26 2
            return CompiledExpression::fromZvalValue(
27 2
                !$compiledExpression->getValue()
28 2
            );
29
        }
30
31
        return new CompiledExpression();
32
    }
33
}
34