Completed
Push — master ( 6cbf5a...04c236 )
by Дмитрий
02:31
created

Minus   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 69.57%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
lcom 0
cbo 4
dl 0
loc 40
ccs 16
cts 23
cp 0.6957
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C compile() 0 28 7
1
<?php
2
/**
3
 * PHP Static Analysis project 2015
4
 *
5
 * @author Patsura Dmitry https://github.com/ovr <[email protected]>
6
 */
7
8
namespace PHPSA\Compiler\Expression\Operators\Arithmetical;
9
10
use PHPSA\CompiledExpression;
11
use PHPSA\Context;
12
use PHPSA\Compiler\Expression;
13
use PHPSA\Compiler\Expression\AbstractExpressionCompiler;
14
15
class Minus extends AbstractExpressionCompiler
16
{
17
    protected $name = 'PhpParser\Node\Expr\BinaryOp\Minus';
18
19
    /**
20
     * {expr} - {expr}
21
     *
22
     * @param \PhpParser\Node\Expr\BinaryOp\Minus $expr
23
     * @param Context $context
24
     * @return CompiledExpression
25
     */
26 18
    protected function compile($expr, Context $context)
27
    {
28 18
        $expression = new Expression($context);
29 18
        $left = $expression->compile($expr->left);
30
31 18
        $expression = new Expression($context);
32 18
        $right = $expression->compile($expr->right);
33
34 18
        switch ($left->getType()) {
35 18
            case CompiledExpression::LNUMBER:
36 17
                switch ($right->getType()) {
37 17
                    case CompiledExpression::LNUMBER:
38 16
                        return new CompiledExpression(CompiledExpression::LNUMBER, $left->getValue() - $right->getValue());
39 1
                    case CompiledExpression::DNUMBER:
40
                        return new CompiledExpression(CompiledExpression::DNUMBER, $left->getValue() - $right->getValue());
41 1
                }
42 1
                break;
43 1
            case CompiledExpression::DNUMBER:
44
                switch ($right->getType()) {
45
                    case CompiledExpression::LNUMBER:
46
                    case CompiledExpression::DNUMBER:
47
                        return new CompiledExpression(CompiledExpression::DNUMBER, $left->getValue() - $right->getValue());
48
                }
49
                break;
50 2
        }
51
52 2
        return new CompiledExpression(CompiledExpression::UNKNOWN);
53
    }
54
}
55