• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pmd / pmd / 218

24 Oct 2025 01:23PM UTC coverage: 78.676% (-0.007%) from 78.683%
218

push

github

web-flow
[plsql] Excessive*/Ncss*Count/NPathComplexity include the metric (#6077)

18267 of 24067 branches covered (75.9%)

Branch coverage included in aggregate %.

8 of 11 new or added lines in 5 files covered. (72.73%)

2 existing lines in 1 file now uncovered.

39803 of 49742 relevant lines covered (80.02%)

0.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

57.69
/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/rule/design/NPathComplexityRule.java
1
/*
2
 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3
 */
4

5
package net.sourceforge.pmd.lang.plsql.rule.design;
6

7
import java.util.List;
8

9
import net.sourceforge.pmd.lang.plsql.ast.ASTConditionalAndExpression;
10
import net.sourceforge.pmd.lang.plsql.ast.ASTConditionalOrExpression;
11
import net.sourceforge.pmd.lang.plsql.ast.ASTExpression;
12
import net.sourceforge.pmd.lang.plsql.ast.ExecutableCode;
13

14
/**
15
 * NPath complexity is a measurement of the acyclic execution paths through a
16
 * function. See Nejmeh, Communications of the ACM Feb 1988 pp 188-200.
17
 *
18
 * @author Jason Bennett
19
 */
20
public class NPathComplexityRule extends AbstractCounterCheckRule<ExecutableCode> {
21

22
    public NPathComplexityRule() {
23
        super(ExecutableCode.class);
1✔
24
    }
1✔
25

26
    @Override
27
    protected int defaultReportLevel() {
28
        return 200;
1✔
29
    }
30

31

32
    @Override
33
    protected int getMetric(ExecutableCode node) {
34
        return new NPathComplexityVisitor().compute(node);
1✔
35
    }
36

37
    @Override
38
    protected Object[] getViolationParameters(ExecutableCode node, int metric, int limit) {
39
        return new Object[] {node.getMethodName(), metric, limit};
1✔
40
    }
41

42
    /**
43
     * @deprecated Since 7.18.0. Use {@link #getViolationParameters(ExecutableCode, int, int)} instead.
44
     */
45
    @Deprecated
46
    protected Object[] getViolationParameters(ExecutableCode node, int metric) {
NEW
47
        return getViolationParameters(node, metric, -1);
×
48
    }
49

50
    /**
51
     * Calculate the boolean complexity of the given expression. NPath boolean
52
     * complexity is the sum of &amp;&amp; and || tokens. This is calculated by summing
53
     * the number of children of the &amp;&amp;'s (minus one) and the children of the
54
     * ||'s (minus one).
55
     *
56
     * <p>Note that this calculation applies to Cyclomatic Complexity as well.</p>
57
     *
58
     * @param expr control structure expression
59
     *
60
     * @return complexity of the boolean expression
61
     */
62
    static int sumExpressionComplexity(ASTExpression expr) {
63
        if (expr == null) {
1!
64
            return 0;
×
65
        }
66

67
        List<ASTConditionalAndExpression> andNodes = expr.descendants(ASTConditionalAndExpression.class).toList();
1✔
68
        List<ASTConditionalOrExpression> orNodes = expr.descendants(ASTConditionalOrExpression.class).toList();
1✔
69

70
        int children = 0;
1✔
71

72
        for (ASTConditionalOrExpression element : orNodes) {
1!
73
            children += element.getNumChildren();
×
74
            children--;
×
75
        }
×
76

77
        for (ASTConditionalAndExpression element : andNodes) {
1!
78
            children += element.getNumChildren();
×
79
            children--;
×
80
        }
×
81

82
        return children;
1✔
83
    }
84
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc