Completed
Push — master ( 348c99...3621ce )
by Enrico
9s
created

DoNotUseGoto::pass()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 3.0032

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 14
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 19
ccs 13
cts 14
cp 0.9286
crap 3.0032
rs 9.4285
1
<?php
2
3
namespace PHPSA\Analyzer\Pass\Statement;
4
5
use PhpParser\Node\Stmt;
6
use PhpParser\Node;
7
use PhpParser\Node\Stmt\Goto_;
8
use PhpParser\Node\Stmt\Label;
9
use PHPSA\Analyzer\Pass;
10
use PHPSA\Context;
11
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
12
13
class DoNotUseGoto implements Pass\ConfigurablePassInterface, Pass\AnalyzerPassInterface
14
{
15
    /**
16
     * @param $stmt
17
     * @param Context $context
18
     * @return bool
19
     */
20 1
    public function pass($stmt, Context $context)
21
    {
22 1
        if ($stmt instanceof Label) {
23 1
            $context->notice(
24 1
                'do_not_use_goto',
25 1
                'Do not use labels',
26
                $stmt
27 1
            );
28 1
            return true;
29 1
        } elseif ($stmt instanceof Goto_) {
30 1
            $context->notice(
31 1
                'do_not_use_goto',
32 1
                'Do not use goto statements',
33
                $stmt
34 1
            );
35 1
            return true;
36
        }
37
        return false;
38
    }
39
40
    /**
41
     * @return TreeBuilder
42
     */
43
    public function getConfiguration()
44
    {
45
        $treeBuilder = new TreeBuilder();
46
        $treeBuilder->root('do_not_use_goto')
47
            ->canBeDisabled();
48
49
        return $treeBuilder;
50
    }
51
52
    /**
53
     * @return array
54
     */
55 1
    public function getRegister()
56
    {
57
        return [
58 1
            Goto_::class,
59 1
            Label::class,
60 1
        ];
61
    }
62
}
63