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

DoNotUseGlobals   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 62.5%

Importance

Changes 0
Metric Value
dl 0
loc 43
ccs 10
cts 16
cp 0.625
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A pass() 0 13 2
A getConfiguration() 0 8 1
A getRegister() 0 6 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\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