WeightedMethodCount::apply()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
ccs 6
cts 6
cp 1
crap 2
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\Design;
19
20
use PHPMD\AbstractNode;
21
use PHPMD\AbstractRule;
22
use PHPMD\Rule\ClassAware;
23
24
/**
25
 * This rule checks a given class against a configured weighted method count
26
 * threshold.
27
 *
28
 * @since      0.2.5
29
 */
30
class WeightedMethodCount extends AbstractRule implements ClassAware
31
{
32
    /**
33
     * This method checks the weighted method count for the given class against
34
     * a configured threshold.
35
     *
36
     * @param \PHPMD\AbstractNode $node
37
     * @return void
38
     */
39 5
    public function apply(AbstractNode $node)
40
    {
41 5
        $threshold = $this->getIntProperty('maximum');
42 5
        $actual    = $node->getMetric('wmc');
43
44 5
        if ($actual >= $threshold) {
45 4
            $this->addViolation($node, array($node->getName(), $actual, $threshold));
46
        }
47 5
    }
48
}
49