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

BitwiseOr   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 31
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
B compile() 0 19 7
1
<?php
2
3
namespace PHPSA\Compiler\Expression\Operators\Bitwise;
4
5
use PHPSA\CompiledExpression;
6
use PHPSA\Context;
7
use PHPSA\Compiler\Expression;
8
use PHPSA\Compiler\Expression\AbstractExpressionCompiler;
9
10
class BitwiseOr extends AbstractExpressionCompiler
11
{
12
    protected $name = 'PhpParser\Node\Expr\BinaryOp\BitwiseOr';
13
14
    /**
15
     * {expr} | {expr}
16
     *
17
     * @param \PhpParser\Node\Expr\BinaryOp\BitwiseOr $expr
18
     * @param Context $context
19
     * @return CompiledExpression
20
     */
21
    protected function compile($expr, Context $context)
22
    {
23
        $left = $context->getExpressionCompiler()->compile($expr->left);
24
        $right = $context->getExpressionCompiler()->compile($expr->right);
25
26
        switch ($left->getType()) {
27
            case CompiledExpression::INTEGER:
28
            case CompiledExpression::DOUBLE:
29
            case CompiledExpression::BOOLEAN:
30
                switch ($right->getType()) {
31
                    case CompiledExpression::INTEGER:
32
                    case CompiledExpression::DOUBLE:
33
                    case CompiledExpression::BOOLEAN:
34
                        return CompiledExpression::fromZvalValue($left->getValue() | $right->getValue());
35
                }
36
        }
37
38
        return new CompiledExpression();
39
    }
40
}
41