LanguageNotes
ABAPThe following keywords increase the complexity by one: AND, CATCH, CONTINUE, DO, ELSEIF, IF, LOOP, LOOPAT, OR, PROVIDE, SELECT…ENDSELECT, TRY, WHEN, WHILE
C/C++/Objective-C

The complexity gets incremented by one for: function definitions, while, do while, for, throw statements, return (except if it is the last statement of a function), switch, case, default, && operator, || operator, ? ternary operator, catch, break, continue, goto.

CobolThe following commands increase the complexity by one: ALSO, ALTER, AND, DEPENDING, END_OF_PAGE, ENTRY, EOP, EXCEPTION, EXIT, GOBACK, CONTINUE, IF, INVALID, OR, OVERFLOW, SIZE, STOP, TIMES, UNTIL, USE, VARYING, WHEN, EXEC CICS HANDLE, EXEC CICS LINK, EXEC CICS XCTL, EXEC CICS RETURN
Java
  • Keywords incrementing the complexity: if, for, while, case, catch, throw, return (that is not the last statement of a method), &&, ||, ?
  • Notes:
    • else, default, and finally keywords do not increment the complexity.
    • a simple method with a switch statement and a huge block of case statements can have a surprisingly high complexity value (still it has the same value when converting a switch block to an equivalent sequence of if statements).
    • accessors are not considered as methods and so do not increment the complexity


Example: the following method has a complexity of 5

public void process(Car myCar){          // +1
    if(myCar.isNotMine()){               // +1
         return;                         // +1
    }
    car.paint("red");
    car.changeWheel();
    while(car.hasGazol() && car.getDriver().isNotStressed()){   // +2
         car.drive();
    }
    return;
}
JavaScript, PHP

Complexity is incremented by one for each:

    • function (i.e non-abstract and non-anonymous constructors, functions, procedures or methods)
    • if statement
    • short-circuit (AKA lazy) logical conjunction (&&)
    • short-circuit (AKA lazy) logical disjunction (||)
    • ternary conditional expressions
    • loop
    • case clauses of a switch statement
    • throw and catch statement
    • return statement (except when it is the very last statement of a function)
    • go to statement (only for PHP)
PL/IThe following keywords increase the complexity by one: PROC, PROCEDURE, GOTO, GO TO, RETURN, DO, IF, WHEN, |, !, |=, !=, &, &=
PL/SQLThe complexity gets incremented by one for: the main PL/SQL anonymous block (not inner ones), create procedure, create trigger, procedure_definition, basic loop statement, when_clause_statement (the “when” of simple_case_statement and searched_case_statement), continue_statement, cursor_for_loop_statement, continue_exit_when_clause (The “WHEN” part of the continue and exit statements), exception_handler (every individual “WHEN”), exit_statement, for_loop_statement, forall_statement, if_statement, elsif_clause, raise_statement, return_statement, while_loop_statement, and_expression (“and” reserved word used within PL/SQL expressions), or_expression (“or” reserved word used within PL/SQL expressions), when_clause_expression (the “when” of simple_case_expression and searched_case_expression)
VB.NETThe complexity gets incremented by one for: method or constructor declaration (Sub, Function), AndAlso, Case, Continue, End, Error, Exit, If, Loop, On Error, GoTo, OrElse, Resume, Return (except if it is the last statement of a function), Stop, Throw, Try.
Web

Complexity of the web page is measured by counting the decision tags (such as if and forEach) and boolean operators in expressions (&& and ||), plus one for the body of the document. The decision tags and the operators are configurable through the Complexity rule.