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

Plus::compile()   C

Complexity

Conditions 9
Paths 21

Size

Total Lines 23
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 90

Importance

Changes 0
Metric Value
cc 9
eloc 16
nc 21
nop 2
dl 0
loc 23
ccs 0
cts 19
cp 0
crap 90
rs 5.8541
c 0
b 0
f 0
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\AssignOp;
9
10
use PHPSA\CompiledExpression;
11
use PHPSA\Compiler\Expression;
12
use PHPSA\Compiler\Expression\AbstractExpressionCompiler;
13
use PHPSA\Context;
14
15
class Plus extends AbstractExpressionCompiler
16
{
17
    protected $name = 'PhpParser\Node\Expr\AssignOp\Plus';
18
19
    /**
20
     * {left-expr} += {right-expr}
21
     *
22
     * @param \PhpParser\Node\Expr\AssignOp\Plus $expr
23
     * @param Context $context
24
     * @return CompiledExpression
25
     */
26
    protected function compile($expr, Context $context)
27
    {
28
        $left = $context->getExpressionCompiler()->compile($expr->var);
29
        $expExpression = $context->getExpressionCompiler()->compile($expr->expr);
30
31
        switch ($left->getType()) {
32
            case CompiledExpression::INTEGER:
33
            case CompiledExpression::DOUBLE:
34
            case CompiledExpression::NUMBER:
35
            case CompiledExpression::BOOLEAN:
36
                switch ($expExpression->getType()) {
37
                    case CompiledExpression::INTEGER:
38
                    case CompiledExpression::DOUBLE:
39
                    case CompiledExpression::NUMBER:
40
                    case CompiledExpression::BOOLEAN:
41
                        return CompiledExpression::fromZvalValue(
42
                            $left->getValue() + $expExpression->getValue()
43
                        );
44
                }
45
        }
46
47
        return new CompiledExpression();
48
    }
49
}
50