Completed
Push — master ( aecd2c...b9491d )
by Дмитрий
09:52 queued 06:00
created

UnaryPlus   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 8
c 3
b 1
f 0
lcom 0
cbo 5
dl 0
loc 35
ccs 18
cts 18
cp 1
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 UnaryPlus extends AbstractExpressionCompiler
16
{
17
    protected $name = 'PhpParser\Node\Expr\UnaryPlus';
18
19
    /**
20
     * -{expr}
21
     *
22
     * @param \PhpParser\Node\Expr\UnaryPlus $expr
23
     * @param Context $context
24
     * @return CompiledExpression
25
     */
26 9
    protected function compile($expr, Context $context)
27
    {
28 9
        $expression = new Expression($context);
29 9
        $left = $expression->compile($expr->expr);
30
31 9
        switch ($left->getType()) {
32 9
            case CompiledExpression::INTEGER:
33 9
            case CompiledExpression::DOUBLE:
34 9
            case CompiledExpression::NUMBER:
35 9
            case CompiledExpression::BOOLEAN:
36 9
            case CompiledExpression::STRING:
37 9
            case CompiledExpression::NULL:
38 8
                return CompiledExpression::fromZvalValue(+$left->getValue());
39 1
            case CompiledExpression::ARR:
40 1
                $context->notice(
41 1
                    'unsupported-operand-types',
42 1
                    'Unsupported operand types -{array}',
43
                    $expr
44 1
                );
45 1
        }
46
47 1
        return new CompiledExpression();
48
    }
49
}
50