Completed
Pull Request — master (#179)
by
unknown
03:46
created

DoNotUseLabels::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 PHPSA\Analyzer\Pass;
8
use PHPSA\Context;
9
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
10
11
class DoNotUseLabels implements Pass\ConfigurablePassInterface, Pass\AnalyzerPassInterface
12
{
13
    /**
14
     * @param Stmt\Label $stmt
15
     * @param Context $context
16
     * @return bool
17
     */
18 2
    public function pass($stmt, Context $context)
19
    {
20 2
        if ($stmt instanceof Stmt\Label) {
21 2
            $context->notice(
22 2
                'do_not_use_labels',
23 2
                'Do not use labels',
24
                $stmt
25 2
            );
26 2
            return true;
27 2
        } elseif ($stmt instanceof Stmt\Goto_) {
28 2
            $context->notice(
29 2
                'do_not_use_goto',
30 2
                'Do not use goto statements',
31
                $stmt
32 2
            );
33 2
            return true;
34
        }
35
        return false;
36
    }
37
38
    /**
39
     * @return TreeBuilder
40
     */
41
    public function getConfiguration()
42
    {
43
        $treeBuilder = new TreeBuilder();
44
        $treeBuilder->root('do_not_use_labels')
45
            ->canBeDisabled();
46
47
        return $treeBuilder;
48
    }
49
50
    /**
51
     * @return array
52
     */
53 1
    public function getRegister()
54
    {
55
        return [
56 1
            Stmt\Goto_::class,
57 1
            Stmt\Label::class,
58 1
        ];
59
    }
60
}
61