Completed
Push — master ( 64a288...be4467 )
by Дмитрий
04:04
created

UnaryMinus   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
dl 0
loc 30
ccs 12
cts 14
cp 0.8571
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
B compile() 0 18 7
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\Operators;
9
10
use PHPSA\CompiledExpression;
11
use PHPSA\Context;
12
use PHPSA\Compiler\Expression;
13
use PHPSA\Compiler\Expression\AbstractExpressionCompiler;
14
15
class UnaryMinus extends AbstractExpressionCompiler
16
{
17
    protected $name = 'PhpParser\Node\Expr\UnaryMinus';
18
19
    /**
20
     * -{expr}
21
     *
22
     * @param \PhpParser\Node\Expr\UnaryMinus $expr
23
     * @param Context $context
24
     * @return CompiledExpression
25
     */
26 1
    protected function compile($expr, Context $context)
27
    {
28 1
        $left = $context->getExpressionCompiler()->compile($expr->expr);
29
30 1
        switch ($left->getType()) {
31 1
            case CompiledExpression::INTEGER:
32 1
            case CompiledExpression::DOUBLE:
33 1
            case CompiledExpression::NUMBER:
34 1
            case CompiledExpression::BOOLEAN:
35 1
            case CompiledExpression::STRING:
36 1
            case CompiledExpression::NULL:
37 1
                return CompiledExpression::fromZvalValue(
38 1
                    - (int) $left->getValue()
39 1
                );
40
        }
41
42
        return new CompiledExpression();
43
    }
44
}
45