Completed
Push — master ( 40ee83...aecd2c )
by Дмитрий
07:12 queued 02:11
created

IfSt   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 10
c 3
b 0
f 0
lcom 0
cbo 6
dl 0
loc 56
ccs 0
cts 34
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
D compile() 0 46 10
1
<?php
2
/**
3
 * @author Patsura Dmitry https://github.com/ovr <[email protected]>
4
 */
5
6
namespace PHPSA\Compiler\Statement;
7
8
use PHPSA\CompiledExpression;
9
use PHPSA\Context;
10
use PHPSA\Compiler\Expression;
11
use PHPSA\Variable;
12
13
class IfSt extends AbstractCompiler
14
{
15
    protected $name = '\PhpParser\Node\Stmt\If_';
16
17
    /**
18
     * @param \PhpParser\Node\Stmt\If_ $ifStatement
19
     * @param Context $context
20
     * @return CompiledExpression
21
     */
22
    public function compile($ifStatement, Context $context)
23
    {
24
        $context->setCurrentBranch(Variable::BRANCH_CONDITIONAL_TRUE);
25
26
        $expression = new Expression($context);
27
        $expression->compile($ifStatement->cond);
28
29
        if (count($ifStatement->stmts) > 0) {
30
            foreach ($ifStatement->stmts as $stmt) {
31
                \PHPSA\nodeVisitorFactory($stmt, $context);
32
            }
33
        } else {
34
            $context->notice('not-implemented-body', 'Missing body', $ifStatement);
35
        }
36
37
        $context->setCurrentBranch(Variable::BRANCH_CONDITIONAL_EXTERNAL);
38
39
        if (count($ifStatement->elseifs) > 0) {
40
            foreach ($ifStatement->elseifs as $elseIfStatement) {
41
                $expression = new Expression($context);
42
                $expression->compile($elseIfStatement->cond);
43
44
                if (count($elseIfStatement->stmts) > 0) {
45
                    foreach ($elseIfStatement->stmts as $stmt) {
46
                        \PHPSA\nodeVisitorFactory($stmt, $context);
47
                    }
48
                } else {
49
                    $context->notice('not-implemented-body', 'Missing body', $elseIfStatement);
50
                }
51
            }
52
        }
53
54
        $context->setCurrentBranch(Variable::BRANCH_CONDITIONAL_FALSE);
55
56
        if ($ifStatement->else) {
57
            if (count($ifStatement->else->stmts) > 0) {
58
                foreach ($ifStatement->else->stmts as $stmt) {
59
                    \PHPSA\nodeVisitorFactory($stmt, $context);
60
                }
61
            } else {
62
                $context->notice('not-implemented-body', 'Missing body', $ifStatement->else);
63
            }
64
        }
65
66
        $context->setCurrentBranch(Variable::BRANCH_ROOT);
67
    }
68
}
69