Completed
Pull Request — master (#132)
by Enrico
05:04
created

ConstantNaming::getConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 9
ccs 0
cts 5
cp 0
crap 2
rs 9.6666
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
    /**
15
     * @param ClassConst $stmt
16
     * @param Context $context
17
     * @return bool
18
     */
19 1
    public function pass(ClassConst $stmt, Context $context)
20
    {
21 1
        if ($stmt->consts[0]->name != strtoupper($stmt->consts[0]->name)) {
22 1
            $context->notice(
23 1
                'constant.naming',
24 1
                'Constant names should be all uppercase.',
25
                $stmt
26 1
            );
27
28 1
            return true;
29
        }
30 1
        return false;
31
    }
32
33
    /**
34
     * @return TreeBuilder
35
     */
36
    public function getConfiguration()
37
    {
38
        $treeBuilder = new TreeBuilder();
39
        $treeBuilder->root('constant_naming')
40
            ->canBeDisabled()
41
        ;
42
43
        return $treeBuilder;
44
    }
45
46
    /**
47
     * @return array
48
     */
49 1
    public function getRegister()
50
    {
51
        return [
52
            \PhpParser\Node\Stmt\ClassConst::class
53 1
        ];
54
    }
55
}
56