Completed
Push — master ( 7c6e4c...cb91d6 )
by Enrico
04:32
created

ConstantNaming   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 36
ccs 14
cts 14
cp 1
rs 10
c 1
b 0
f 0
wmc 4
lcom 0
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A pass() 0 18 3
A getRegister() 0 6 1
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\Context;
8
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
9
10
class ConstantNaming implements AnalyzerPassInterface
11
{
12
    /**
13
     * @param ClassConst $stmt
14
     * @param Context $context
15
     * @return bool
16
     */
17 1
    public function pass(ClassConst $stmt, Context $context)
18
    {
19 1
        $result = false;
20
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 array
38
     */
39 1
    public function getRegister()
40
    {
41
        return [
42
            ClassConst::class
43 1
        ];
44
    }
45
}
46