Completed
Pull Request — master (#132)
by Enrico
02:58
created

ConstantNaming   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 73.68%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 48
ccs 14
cts 19
cp 0.7368
rs 10
wmc 5
lcom 0
cbo 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfiguration() 0 9 1
A getRegister() 0 6 1
A pass() 0 17 3
1
<?php
2
3
namespace PHPSA\Analyzer\Pass\Statement;
4
5
use PhpParser\Node\Stmt\ClassConst;
6
use PHPSA\Analyzer\Pass\AnalyzerPassInterface;
7
use PHPSA\Analyzer\Pass\ConfigurablePassInterface;
8
use PHPSA\Context;
9
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
10
11
class ConstantNaming implements ConfigurablePassInterface, AnalyzerPassInterface
12
{
13
    /**
14
     * @param ClassConst $stmt
15
     * @param Context $context
16
     * @return bool
17
     */
18 1
    public function pass(ClassConst $stmt, Context $context)
19
    {
20 1
        $result = false;
21 1
        foreach ($stmt->consts as $const) {
22 1
            if ($const->name !== strtoupper($const->name)) {
23 1
                $context->notice(
24 1
                    'constant.naming',
25 1
                    'Constant names should be all uppercase.',
26
                    $stmt
27 1
                );
28
29 1
                $result = true;
30 1
            }
31 1
        }
32
        
33 1
        return $result;
34
    }
35
36
    /**
37
     * @return TreeBuilder
38
     */
39
    public function getConfiguration()
40
    {
41
        $treeBuilder = new TreeBuilder();
42
        $treeBuilder->root('constant_naming')
43
            ->canBeDisabled()
44
        ;
45
46
        return $treeBuilder;
47
    }
48
49
    /**
50
     * @return array
51
     */
52 1
    public function getRegister()
53
    {
54
        return [
55
            ClassConst::class
56 1
        ];
57
    }
58
}
59