Completed
Pull Request — master (#149)
by Enrico
03:51
created

IfSt   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 54
ccs 30
cts 32
cp 0.9375
rs 10
wmc 10
lcom 0
cbo 6

1 Method

Rating   Name   Duplication   Size   Complexity  
D compile() 0 44 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\Variable;
11
12
class IfSt extends AbstractCompiler
13
{
14
    protected $name = '\PhpParser\Node\Stmt\If_';
15
16
    /**
17
     * @param \PhpParser\Node\Stmt\If_ $ifStatement
18
     * @param Context $context
19
     * @return CompiledExpression
20
     */
21 4
    public function compile($ifStatement, Context $context)
22
    {
23 4
        $context->setCurrentBranch(Variable::BRANCH_CONDITIONAL_TRUE);
24
25 4
        $context->getExpressionCompiler()->compile($ifStatement->cond);
26
27 4
        if (count($ifStatement->stmts) > 0) {
28 1
            foreach ($ifStatement->stmts as $stmt) {
29 1
                \PHPSA\nodeVisitorFactory($stmt, $context);
30 1
            }
31 1
        } else {
32 3
            $context->notice('not-implemented-body', 'Missing body', $ifStatement);
33
        }
34
35 4
        $context->setCurrentBranch(Variable::BRANCH_CONDITIONAL_EXTERNAL);
36
37 4
        if (count($ifStatement->elseifs) > 0) {
38 1
            foreach ($ifStatement->elseifs as $elseIfStatement) {
39 1
                $context->getExpressionCompiler()->compile($elseIfStatement->cond);
40
41 1
                if (count($elseIfStatement->stmts) > 0) {
42 1
                    foreach ($elseIfStatement->stmts as $stmt) {
43 1
                        \PHPSA\nodeVisitorFactory($stmt, $context);
44 1
                    }
45 1
                } else {
46
                    $context->notice('not-implemented-body', 'Missing body', $elseIfStatement);
47
                }
48 1
            }
49 1
        }
50
51 4
        $context->setCurrentBranch(Variable::BRANCH_CONDITIONAL_FALSE);
52
53 4
        if ($ifStatement->else) {
54 1
            if (count($ifStatement->else->stmts) > 0) {
55 1
                foreach ($ifStatement->else->stmts as $stmt) {
56 1
                    \PHPSA\nodeVisitorFactory($stmt, $context);
57 1
                }
58 1
            } else {
59
                $context->notice('not-implemented-body', 'Missing body', $ifStatement->else);
60
            }
61 1
        }
62
63 4
        $context->setCurrentBranch(Variable::BRANCH_ROOT);
64 4
    }
65
}
66