Completed
Push — master ( 7e1c48...853d12 )
by Дмитрий
03:20
created

SwitchSt::compile()   B

Complexity

Conditions 6
Paths 8

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 6.0087

Importance

Changes 3
Bugs 1 Features 0
Metric Value
cc 6
eloc 11
c 3
b 1
f 0
nc 8
nop 2
dl 0
loc 20
ccs 15
cts 16
cp 0.9375
crap 6.0087
rs 8.8571
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
11
class SwitchSt extends AbstractCompiler
12
{
13
    protected $name = '\PhpParser\Node\Stmt\Switch_';
14
15
    /**
16
     * @param \PhpParser\Node\Stmt\Switch_ $stmt
17
     * @param Context $context
18
     * @return CompiledExpression
19
     */
20 1
    public function compile($stmt, Context $context)
21
    {
22 1
        $context->getExpressionCompiler()->compile($stmt->cond);
23
24 1
        if (count($stmt->cases)) {
25 1
            foreach ($stmt->cases as $case) {
26 1
                if ($case->cond) {
27 1
                    $context->getExpressionCompiler()->compile($case->cond);
28 1
                }
29
30 1
                if (count($case->stmts)) {
31 1
                    foreach ($case->stmts as $caseStatements) {
32 1
                        \PHPSA\nodeVisitorFactory($caseStatements, $context);
33 1
                    }
34 1
                }
35 1
            }
36 1
        } else {
37
            $context->notice('switch.empty', 'Switch block is empty, lol', $stmt);
38
        }
39 1
    }
40
}
41