IfSt   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 34
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A compile() 0 24 4
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
    public function compile($ifStatement, Context $context)
22
    {
23
        $context->setCurrentBranch(Variable::BRANCH_CONDITIONAL_TRUE);
24
25
        $context->getExpressionCompiler()->compile($ifStatement->cond);
26
27
        foreach ($ifStatement->stmts as $stmt) {
28
            \PHPSA\nodeVisitorFactory($stmt, $context);
29
        }
30
31
        $context->setCurrentBranch(Variable::BRANCH_CONDITIONAL_EXTERNAL);
32
33
        foreach ($ifStatement->elseifs as $elseIfStatement) {
34
            \PHPSA\nodeVisitorFactory($elseIfStatement, $context);
35
        }
36
37
        $context->setCurrentBranch(Variable::BRANCH_CONDITIONAL_FALSE);
38
39
        if ($ifStatement->else) {
40
            \PHPSA\nodeVisitorFactory($ifStatement->else, $context);
41
        }
42
43
        $context->setCurrentBranch(Variable::BRANCH_ROOT);
44
    }
45
}
46