Code Duplication    Length = 26-28 lines in 5 locations

src/main/php/PHPMD/Rule/CyclomaticComplexity.php 1 location

@@ 27-54 (lines=28) @@
24
 * This rule checks a given method or function against the configured cyclomatic
25
 * complexity threshold.
26
 */
27
class CyclomaticComplexity extends AbstractRule implements FunctionAware, MethodAware
28
{
29
    /**
30
     * This method checks the cyclomatic complexity for the given node against
31
     * a configured threshold.
32
     *
33
     * @param \PHPMD\AbstractNode $node
34
     * @return void
35
     */
36
    public function apply(AbstractNode $node)
37
    {
38
        $threshold = $this->getIntProperty('reportLevel');
39
        $ccn = $node->getMetric('ccn2');
40
        if ($ccn < $threshold) {
41
            return;
42
        }
43
44
        $this->addViolation(
45
            $node,
46
            array(
47
                $node->getType(),
48
                $node->getName(),
49
                $ccn,
50
                $threshold
51
            )
52
        );
53
    }
54
}
55

src/main/php/PHPMD/Rule/Design/NpathComplexity.php 1 location

@@ 29-56 (lines=28) @@
26
 * This rule will check the NPath-complexity of a method or function against the
27
 * configured threshold.
28
 */
29
class NpathComplexity extends AbstractRule implements FunctionAware, MethodAware
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
    public function apply(AbstractNode $node)
39
    {
40
        $threshold = $this->getIntProperty('minimum');
41
        $npath = $node->getMetric('npath');
42
        if ($npath < $threshold) {
43
            return;
44
        }
45
46
        $this->addViolation(
47
            $node,
48
            array(
49
                $node->getType(),
50
                $node->getName(),
51
                $npath,
52
                $threshold
53
            )
54
        );
55
    }
56
}
57

src/main/php/PHPMD/Rule/Design/NumberOfChildren.php 1 location

@@ 27-52 (lines=26) @@
24
/**
25
 * This rule will detect class that have to much direct child classes.
26
 */
27
class NumberOfChildren extends AbstractRule implements ClassAware
28
{
29
    /**
30
     * This method checks the number of classes derived from the given class
31
     * node.
32
     *
33
     * @param \PHPMD\AbstractNode $node
34
     * @return void
35
     */
36
    public function apply(AbstractNode $node)
37
    {
38
        $nocc = $node->getMetric('nocc');
39
        $threshold = $this->getIntProperty('minimum');
40
        if ($nocc >= $threshold) {
41
            $this->addViolation(
42
                $node,
43
                array(
44
                    $node->getType(),
45
                    $node->getName(),
46
                    $nocc,
47
                    $threshold
48
                )
49
            );
50
        }
51
    }
52
}
53

src/main/php/PHPMD/Rule/Design/TooManyFields.php 1 location

@@ 27-53 (lines=27) @@
24
/**
25
 * This rule class will detect all classes with too much fields.
26
 */
27
class TooManyFields extends AbstractRule implements ClassAware
28
{
29
    /**
30
     * This method checks the number of methods with in a given class and checks
31
     * this number against a configured threshold.
32
     *
33
     * @param \PHPMD\AbstractNode $node
34
     * @return void
35
     */
36
    public function apply(AbstractNode $node)
37
    {
38
        $threshold = $this->getIntProperty('maxfields');
39
        $vars = $node->getMetric('vars');
40
        if ($vars <= $threshold) {
41
            return;
42
        }
43
        $this->addViolation(
44
            $node,
45
            array(
46
                $node->getType(),
47
                $node->getName(),
48
                $vars,
49
                $threshold
50
            )
51
        );
52
    }
53
}
54

src/main/php/PHPMD/Rule/ExcessivePublicCount.php 1 location

@@ 27-53 (lines=27) @@
24
 * This rule checks the number of public methods and fields in a given class.
25
 * Then it compares the number of public members against a configured threshold.
26
 */
27
class ExcessivePublicCount extends AbstractRule implements ClassAware
28
{
29
    /**
30
     * This method checks the number of public fields and methods in the given
31
     * class and checks that value against a configured threshold.
32
     *
33
     * @param \PHPMD\AbstractNode $node
34
     * @return void
35
     */
36
    public function apply(AbstractNode $node)
37
    {
38
        $threshold = $this->getIntProperty('minimum');
39
        $cis = $node->getMetric('cis');
40
        if ($cis < $threshold) {
41
            return;
42
        }
43
        $this->addViolation(
44
            $node,
45
            array(
46
                $node->getType(),
47
                $node->getName(),
48
                $cis,
49
                $threshold
50
            )
51
        );
52
    }
53
}
54