Back to all rules
What this rule checks
Code cognitive complexity within limits (threshold: 10)
Configuration
When off, this rule is excluded from pipeline runs. Changes apply immediately.
Code Examples
PASS — this code satisfies the rule
void setup() {
  size(400, 400);
}

void draw() {
  background(255);
  for (int x = 0; x < width; x += 40) {
    if (x < mouseX) {
      fill(0);
    } else {
      fill(255);
    }
    rect(x, 180, 40, 40);
  }
}
FAIL — this code triggers the rule
void setup() {
  size(400, 400);
}

void draw() {
  for (int x = 0; x < width; x += 40) {
    for (int y = 0; y < height; y += 40) {
      if (x == y) {
        fill(255, 0, 0);
      } else if (mousePressed) {
        if (x < mouseX && y < mouseY) {  // nesting makes it hard to follow
          fill(0);
        } else {
          fill(255);
        }
      }
      rect(x, y, 40, 40);
    }
  }
}
Overview
Category PDPS
Type Built-in PMD
Priority 3 (1 = highest, 5 = lowest)
Status Active
PMD Configuration
PMD reference category/java/design.xml/CognitiveComplexity
Message template Consider reviewing or refactoring for clarity.
Properties
reportLevel = 10