Completed
Push — master ( f7db50...090344 )
by Дмитрий
03:31
created

UnaryMinus   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 8
c 1
b 1
f 0
lcom 0
cbo 5
dl 0
loc 35
ccs 0
cts 18
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C compile() 0 23 8
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;
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
    protected function compile($expr, Context $context)
27
    {
28
        $expression = new Expression($context);
29
        $left = $expression->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
            case CompiledExpression::STRING:
37
            case CompiledExpression::NULL:
38
                return CompiledExpression::fromZvalValue(-$left->getValue());
39
            case CompiledExpression::ARR:
40
                $context->notice(
41
                    'unsupported-operand-types',
42
                    'Unsupported operand types -{array}',
43
                    $expr
44
                );
45
        }
46
47
        return new CompiledExpression();
48
    }
49
}
50