Passed
Pull Request — master (#18)
by Andru
04:16 queued 12s
created

DepthOfInheritance::apply()   B

Complexity

Conditions 6
Paths 4

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 6.0087

Importance

Changes 0
Metric Value
cc 6
nc 4
nop 1
dl 0
loc 25
ccs 15
cts 16
cp 0.9375
crap 6.0087
rs 8.8977
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\ClassAware;
23
24
/**
25
 * This rule will detect classes that are to deep in the inheritance tree.
26
 */
27
class DepthOfInheritance extends AbstractRule implements ClassAware
28
{
29
    /**
30
     * This method checks the number of parents for the given class
31
     * node.
32
     *
33
     * @param \PHPMD\AbstractNode $node
34
     * @return void
35
     */
36 4
    public function apply(AbstractNode $node)
37
    {
38
        try {
39 4
            $threshold = $this->getIntProperty('maximum');
40
            $comparision = 1;
41 4
        } catch (\OutOfBoundsException $e) {
42 4
            $threshold = $this->getIntProperty('minimum');
43 4
            $comparision = 2;
44
        }
45
46 4
        $dit = $node->getMetric('dit');
47 4
        if (($comparision === 1 && $dit > $threshold) ||
48 4
            ($comparision === 2 && $dit >= $threshold)
49
        ) {
50 2
            $this->addViolation(
51 2
                $node,
52
                array(
53 2
                    $node->getType(),
54 2
                    $node->getName(),
55 2
                    $dit,
56 2
                    $threshold
57
                )
58
            );
59
        }
60 4
    }
61
}
62