CamelCaseClassName::apply()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
ccs 0
cts 11
cp 0
crap 6
1
<?php
2
/**
3
 * This file is part of PHP Mess Detector.
4
 *
5
 * Copyright (c) Manuel Pichler <[email protected]>.
6
 * All rights reserved.
7
 *
8
 * Licensed under BSD License
9
 * For full copyright and license information, please see the LICENSE file.
10
 * Redistributions of files must retain the above copyright notice.
11
 *
12
 * @author Manuel Pichler <[email protected]>
13
 * @copyright Manuel Pichler. All rights reserved.
14
 * @license https://opensource.org/licenses/bsd-license.php BSD License
15
 * @link http://phpmd.org/
16
 */
17
18
namespace PHPMD\Rule\Controversial;
19
20
use PHPMD\AbstractNode;
21
use PHPMD\AbstractRule;
22
use PHPMD\Rule\ClassAware;
23
use PHPMD\Rule\InterfaceAware;
24
25
/**
26
 * This rule class detects classes not named in CamelCase.
27
 *
28
 * @author     Francis Besset <[email protected]>
29
 * @since      1.1.0
30
 */
31
class CamelCaseClassName extends AbstractRule implements ClassAware, InterfaceAware
32
{
33
    /**
34
     * This method checks if a class is not named in CamelCase
35
     * and emits a rule violation.
36
     *
37
     * @param \PHPMD\AbstractNode $node
38
     * @return void
39
     */
40
    public function apply(AbstractNode $node)
41
    {
42
        if (!preg_match('/^[A-Z][a-zA-Z0-9]*$/', $node->getName())) {
43
            $this->addViolation(
44
                $node,
45
                array(
46
                    $node->getName(),
47
                )
48
            );
49
        }
50
    }
51
}
52