Passed
Push — master ( 35f862...430807 )
by Andru
03:45
created

DepthOfInheritance   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
dl 0
loc 35
ccs 15
cts 16
cp 0.9375
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
B apply() 0 25 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\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