NpathComplexity::apply()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18

Duplication

Lines 18
Ratio 100 %

Code Coverage

Tests 12
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 18
loc 18
ccs 12
cts 12
cp 1
crap 2
rs 9.6666
c 0
b 0
f 0
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\FunctionAware;
23
use PHPMD\Rule\MethodAware;
24
25
/**
26
 * This rule will check the NPath-complexity of a method or function against the
27
 * configured threshold.
28
 */
29 View Code Duplication
class NpathComplexity extends AbstractRule implements FunctionAware, MethodAware
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
30
{
31
    /**
32
     * This method checks the acyclic complexity for the given node against a
33
     * configured threshold.
34
     *
35
     * @param \PHPMD\AbstractNode $node
36
     * @return void
37
     */
38 5
    public function apply(AbstractNode $node)
39
    {
40 5
        $threshold = $this->getIntProperty('minimum');
41 5
        $npath = $node->getMetric('npath');
42 5
        if ($npath < $threshold) {
43 3
            return;
44
        }
45
46 2
        $this->addViolation(
47 2
            $node,
48
            array(
49 2
                $node->getType(),
50 2
                $node->getName(),
51 2
                $npath,
52 2
                $threshold
53
            )
54
        );
55 2
    }
56
}
57