Internet Toolset

Comprehensive Tools for Webmasters, Developers & Site Optimization

Cyclomatic Complexity Analyzer

Cyclomatic Complexity Analyzer

Flag functions above this value.
Description & Learning Section

Cyclomatic Complexity measures how many independent paths exist through your function. It starts at 1 and increments for each decision point:

  • if, elif, for, while, case, catch
  • Logical operators: &&, ||
  • Ternary ?: expressions

High complexity (>10) often indicates code that is hard to test and maintain. This tool:

  1. Detects Python def, JS function, ES6 arrow functions, and simple class methods.
  2. Computes each function’s complexity and flags those above your threshold.
  3. Aggregates overall metrics: sum, min, max, average, median.
  4. Displays a per‑function list sorted by complexity and a simple histogram.

Example (JS):

function foo(x) {
    if (x > 0 && x < 10) {
        return x % 2 === 0 ? 'even' : 'odd';
    }
    return null;
}
    

Complexity = 1 (base) + 1 (if) + 1 (&&) + 1 (ternary) = 4

Use this tool to pinpoint the most complex functions, guide refactoring, and keep your codebase maintainable.