@Test public void nested_if_statements() { assertThat(complexity("if (x) { 42 };").value()).isEqualTo(1); assertThat(complexity("if (x) { 42 } else { 43 };").value()).isEqualTo(2); assertThat(complexity("if (x) { 42 } else if (y) { 43 };").value()).isEqualTo(2); assertThat(complexity("if (x) { 42 } else if (y) { if (y) { 43 } else { 44 } };").value()).isEqualTo(5); assertThat(complexity("if (x) { 42 } else if (y) { 43 } else { 44 };").value()).isEqualTo(3); assertThat(complexity("if (x) { 42 } else if (y) { 43 } else { if (y) { 44 } else { 45 } };").value()).isEqualTo(6); }
public int value() { int total = 0; for (Increment increment : increments) { total += increment.nestingLevel + 1; } return total; }
CognitiveComplexity { public int value() { int total = 0; for (Increment increment : increments) { total += increment.nestingLevel + 1; } return total; } }
CognitiveComplexity { public int value() { int total = 0; for (Increment increment : increments) { total += increment.nestingLevel + 1; } return total; } CognitiveComplexity(Tree root); }
CognitiveComplexity { public int value() { int total = 0; for (Increment increment : increments) { total += increment.nestingLevel + 1; } return total; } CognitiveComplexity(Tree root); int value(); List<Increment> increments(); }
CognitiveComplexity { public int value() { int total = 0; for (Increment increment : increments) { total += increment.nestingLevel + 1; } return total; } CognitiveComplexity(Tree root); int value(); List<Increment> increments();  }