Completed
Push — master ( 5a98e1...9d14a0 )
by Дмитрий
02:33
created

ShiftRight   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 32
ccs 0
cts 16
cp 0
rs 10
wmc 7
lcom 0
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
B compile() 0 20 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 ShiftRight extends AbstractExpressionCompiler
11
{
12
    protected $name = 'PhpParser\Node\Expr\BinaryOp\ShiftRight';
13
14
    /**
15
     * {expr} >> {expr}
16
     *
17
     * @param \PhpParser\Node\Expr\BinaryOp\ShiftRight $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 new CompiledExpression(CompiledExpression::INTEGER, $left->getValue() >> $right->getValue());
35
                }
36
                break;
37
        }
38
39
        return new CompiledExpression();
40
    }
41
}
42