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

ShiftLeft::compile()   B

Complexity

Conditions 7
Paths 13

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 7
eloc 14
c 3
b 0
f 0
nc 13
nop 2
dl 0
loc 20
ccs 0
cts 16
cp 0
crap 56
rs 8.2222
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 ShiftLeft extends AbstractExpressionCompiler
11
{
12
    protected $name = 'PhpParser\Node\Expr\BinaryOp\ShiftLeft';
13
14
    /**
15
     * {expr} << {expr}
16
     *
17
     * @param \PhpParser\Node\Expr\BinaryOp\ShiftLeft $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