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

Minus::compile()   C

Complexity

Conditions 7
Paths 7

Size

Total Lines 28
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 8.3807

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 28
ccs 16
cts 23
cp 0.6957
rs 6.7273
c 1
b 0
f 0
cc 7
eloc 20
nc 7
nop 2
crap 8.3807
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