ConstantNaming   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 40
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 4

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\Helper\DefaultMetadataPassTrait;
7
use PHPSA\Analyzer\Pass\AnalyzerPassInterface;
8
use PHPSA\Context;
9
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
10
11
class ConstantNaming implements AnalyzerPassInterface
12
{
13
    use DefaultMetadataPassTrait;
14
15
    const DESCRIPTION = 'Checks that constants are all uppercase.';
16
17
    /**
18
     * @param ClassConst $stmt
19
     * @param Context $context
20
     * @return bool
21
     */
22
    public function pass(ClassConst $stmt, Context $context)
23
    {
24
        $result = false;
25
26
        foreach ($stmt->consts as $const) {
27
            if ($const->name != strtoupper($const->name)) {
28
                $context->notice(
29
                    'constant.naming',
30
                    'Constant names should be all uppercase.',
31
                    $stmt
32
                );
33
34
                $result = true;
35
            }
36
        }
37
38
        return $result;
39
    }
40
41
    /**
42
     * @return array
43
     */
44
    public function getRegister()
45
    {
46
        return [
47
            ClassConst::class
48
        ];
49
    }
50
}
51