Completed
Pull Request — master (#213)
by Michele
05:00
created

DoNotUseGlobals::getConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 8
ccs 0
cts 5
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\Global_;
8
use PHPSA\Analyzer\Pass;
9
use PHPSA\Context;
10
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
11
12
class DoNotUseGlobals implements Pass\ConfigurablePassInterface, Pass\AnalyzerPassInterface
13
{
14
    /**
15
     * @param $stmt
16
     * @param Context $context
17
     * @return bool
18
     */
19 2
    public function pass($stmt, Context $context)
20
    {
21 2
        if ($stmt instanceof Global_) {
22 2
            $context->notice(
23 2
                'do_not_use_globals',
24 2
                'Do not use globals',
25
                $stmt
26 2
            );
27 2
            return true;
28
        }
29
30
        return false;
31
    }
32
33
    /**
34
     * @return TreeBuilder
35
     */
36
    public function getConfiguration()
37
    {
38
        $treeBuilder = new TreeBuilder();
39
        $treeBuilder->root('do_not_use_globals')
40
            ->canBeDisabled();
41
42
        return $treeBuilder;
43
    }
44
45
    /**
46
     * @return array
47
     */
48 1
    public function getRegister()
49
    {
50
        return [
51 1
            Global_::class,
52 1
        ];
53
    }
54
}
55