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

ConstantNaming::pass()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 10
nc 3
nop 2
dl 0
loc 18
ccs 12
cts 12
cp 1
crap 3
rs 9.4285
c 1
b 0
f 0
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