Completed
Pull Request — master (#194)
by Enrico
07:43
created

IfSt   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 40
ccs 21
cts 21
cp 1
rs 10
wmc 6
lcom 0
cbo 4

1 Method

Rating   Name   Duplication   Size   Complexity  
B compile() 0 30 6
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 8
    public function compile($ifStatement, Context $context)
22
    {
23 8
        $context->setCurrentBranch(Variable::BRANCH_CONDITIONAL_TRUE);
24
25 8
        $context->getExpressionCompiler()->compile($ifStatement->cond);
26
27 8
        if (count($ifStatement->stmts) > 0) {
28 5
            foreach ($ifStatement->stmts as $stmt) {
29 5
                \PHPSA\nodeVisitorFactory($stmt, $context);
30 5
            }
31 5
        } else {
32 3
            $context->notice('not-implemented-body', 'Missing body', $ifStatement);
33
        }
34
35 8
        $context->setCurrentBranch(Variable::BRANCH_CONDITIONAL_EXTERNAL);
36
37 8
        if (count($ifStatement->elseifs) > 0) {
38 3
            foreach ($ifStatement->elseifs as $elseIfStatement) {
39 3
                \PHPSA\nodeVisitorFactory($elseIfStatement, $context);
40 3
            }
41 3
        }
42
43 8
        $context->setCurrentBranch(Variable::BRANCH_CONDITIONAL_FALSE);
44
45 8
        if ($ifStatement->else) {
46 2
            \PHPSA\nodeVisitorFactory($ifStatement->else, $context);
47 2
        }
48
49 8
        $context->setCurrentBranch(Variable::BRANCH_ROOT);
50 8
    }
51
}
52