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

DoNotUseGlobals::pass()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2.0078

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 2
dl 0
loc 13
ccs 7
cts 8
cp 0.875
crap 2.0078
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