Completed
Push — master ( b396b0...780c87 )
by Дмитрий
02:54
created

SwitchSt   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 9
c 2
b 0
f 0
lcom 0
cbo 4
dl 0
loc 48
ccs 0
cts 28
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
D compile() 0 38 9
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\Definition\ClassMethod;
11
use PHPSA\Compiler\Expression;
12
13
class SwitchSt extends AbstractCompiler
14
{
15
    protected $name = '\PhpParser\Node\Stmt\Switch_';
16
17
    /**
18
     * @param \PhpParser\Node\Stmt\Switch_ $stmt
19
     * @param Context $context
20
     * @return CompiledExpression
21
     */
22
    public function compile($stmt, Context $context)
23
    {
24
        $expression = new Expression($context);
25
        $expression->compile($stmt->cond);
26
27
        if (count($stmt->cases)) {
28
            foreach ($stmt->cases as $case) {
29
                if ($case->cond) {
30
                    $expression = new Expression($context);
31
                    $expression->compile($case->cond);
32
                }
33
34
                if (count($case->stmts) > 0) {
35
                    $beforeStatement = false;
36
37
                    foreach ($case->stmts as $stmt) {
38
                        \PHPSA\nodeVisitorFactory($stmt, $context);
39
40
                        if ($beforeStatement) {
41
                            if ($beforeStatement instanceof \PhpParser\Node\Stmt\Return_
42
                                && $stmt instanceof \PhpParser\Node\Stmt\Break_) {
43
                                $context->notice(
44
                                    'switch.unneeded-break',
45
                                    'Break after return statement is not needed',
46
                                    $stmt
47
                                );
48
                            }
49
                        }
50
                        $beforeStatement = $stmt;
51
                    }
52
                } else {
53
                    $context->notice('not-implemented-body', 'Missing body', $case);
54
                }
55
            }
56
        } else {
57
            //@todo implement
58
        }
59
    }
60
}
61