Completed
Push — master ( 3708b9...fb0aff )
by Enrico
03:36
created

GotoUsage   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 94.44%

Importance

Changes 0
Metric Value
dl 0
loc 38
ccs 17
cts 18
cp 0.9444
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A pass() 0 19 3
A getRegister() 0 7 1
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
12
class GotoUsage implements Pass\AnalyzerPassInterface
13
{
14
    /**
15
     * @param $stmt
16
     * @param Context $context
17
     * @return bool
18
     */
19 1
    public function pass($stmt, Context $context)
20
    {
21 1
        if ($stmt instanceof Label) {
22 1
            $context->notice(
23 1
                'goto_usage',
24 1
                'Do not use labels',
25
                $stmt
26 1
            );
27 1
            return true;
28 1
        } elseif ($stmt instanceof Goto_) {
29 1
            $context->notice(
30 1
                'goto_usage',
31 1
                'Do not use goto statements',
32
                $stmt
33 1
            );
34 1
            return true;
35
        }
36
        return false;
37
    }
38
39
    /**
40
     * @return array
41
     */
42 1
    public function getRegister()
43
    {
44
        return [
45 1
            Goto_::class,
46 1
            Label::class,
47 1
        ];
48
    }
49
}
50