Completed
Push — master ( 361c7d...1d8c7b )
by Enrico
16s
created

PostInc   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 48%

Importance

Changes 0
Metric Value
dl 0
loc 45
ccs 12
cts 25
cp 0.48
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 6

1 Method

Rating   Name   Duplication   Size   Complexity  
B compile() 0 33 6
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 PostInc extends AbstractExpressionCompiler
16
{
17
    protected $name = 'PhpParser\Node\Expr\PostInc';
18
19
    /**
20
     * {expr}++
21
     *
22
     * @param \PhpParser\Node\Expr\PostInc $expr
23
     * @param Context $context
24
     * @return CompiledExpression
25
     */
26 11
    protected function compile($expr, Context $context)
27
    {
28 11
        if ($expr->var instanceof \PHPParser\Node\Expr\Variable) {
29 11
            $variableName = (string)$expr->var->name;
30 11
            $variable = $context->getSymbol($variableName);
31 11
            if ($variable) {
32 11
                $variable->incUse();
33
34 11
                switch ($variable->getType()) {
35 11
                    case CompiledExpression::INTEGER:
36 11
                    case CompiledExpression::DOUBLE:
37 11
                    case CompiledExpression::NUMBER:
38 11
                        $variable->inc();
39 11
                        return CompiledExpression::fromZvalValue($variable->getValue());
40
                }
41
42
                $context->notice(
43
                    'language_error',
44
                    'You are trying to use post increment operator on variable $' . $variableName .
45
                    ' with type: ' . $variable->getTypeName(),
46
                    $expr
47
                );
48
            } else {
49
                $context->notice(
50
                    'language_error',
51
                    'You are trying to use post increment operator on undefined variable: ' . $variableName,
52
                    $expr
53
                );
54
            }
55
        }
56
57
        return new CompiledExpression();
58
    }
59
}
60