Completed
Pull Request — master (#210)
by Дмитрий
03:50
created

DoNotUseGoto::getRegister()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
ccs 0
cts 0
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
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 1
     * @return bool
19
     */
20 1
    public function pass($stmt, Context $context)
21
    {
22 1
        if ($stmt instanceof Label) {
23
            $context->notice(
24
                'do_not_use_goto',
25
                'Do not use labels',
26
                $stmt
27
            );
28
            return true;
29
        } elseif ($stmt instanceof Goto_) {
30
            $context->notice(
31
                'do_not_use_goto',
32
                'Do not use goto statements',
33
                $stmt
34
            );
35
            return true;
36
        }
37
        return false;
38
    }
39
40
    /**
41 1
     * @return TreeBuilder
42
     */
43
    public function getConfiguration()
44 1
    {
45 1
        $treeBuilder = new TreeBuilder();
46
        $treeBuilder->root('do_not_use_goto')
47
            ->canBeDisabled();
48
49
        return $treeBuilder;
50
    }
51
52
    /**
53
     * @return array
54
     */
55
    public function getRegister()
56
    {
57
        return [
58
            Goto_::class,
59
            Label::class,
60
        ];
61
    }
62
}
63