Completed
Push — master ( 66f425...8df3f4 )
by Дмитрий
15:03
created

Plus   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
c 1
b 0
f 1
lcom 0
cbo 4
dl 0
loc 40
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C compile() 0 27 7
1
<?php
2
/**
3
 * PHP Static 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
     * It's used in conditions
21
     * {left-expr} += {right-expr}
22
     *
23
     * @param \PhpParser\Node\Expr\AssignOp\Plus $expr
24
     * @param Context $context
25
     * @return CompiledExpression
26
     */
27
    protected function compile($expr, Context $context)
28
    {
29
        $expression = new Expression($context);
30
        $left = $expression->compile($expr->var);
31
32
        $expression = new Expression($context);
33
        $expExpression = $expression->compile($expr->expr);
34
35
36
        switch ($left->getType()) {
37
            case CompiledExpression::INTEGER:
38
            case CompiledExpression::DOUBLE:
39
            case CompiledExpression::NUMBER:
40
                switch ($expExpression->getType()) {
41
                    case CompiledExpression::INTEGER:
42
                    case CompiledExpression::DOUBLE:
43
                    case CompiledExpression::NUMBER:
44
                        return CompiledExpression::fromZvalValue(
45
                            $left->getValue() + $expExpression->getValue()
46
                        );
47
                        break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
48
                }
49
                break;
50
        }
51
52
        return $left;
53
    }
54
}
55