Categories

Code Complexity Analyzer

Measure cyclomatic and cognitive complexity across multiple programming languages

Analyze source code quality with cross-language complexity heuristics.

Checks included

  • Cyclomatic complexity
  • Cognitive complexity
  • Long functions
  • Deep nesting
  • Duplicate code windows
  • Improvement suggestions

Example Results

2 examples

Analyze a branch-heavy JavaScript function

Measure cyclomatic and cognitive complexity for a nested pricing function using tight thresholds.

{
  "summary": {
    "language": "javascript",
    "functionCount": 1,
    "averageCyclomaticComplexity": 5,
    "averageCognitiveComplexity": 4,
    "hotspotCount": 0,
    "longFunctionCount": 0,
    "deepNestingCount": 1,
    "duplicateClusters": 0
  },
  "functions": [
    {
      "name": "score",
      "cyclomaticComplexity": 5,
      "deepNesting": true
    }
  ]
}
View input parameters
{ "sourceCode": "function score(order) {\n if (!order) return 0;\n let total = 0;\n for (const item of order.items) {\n if (item.discount) {\n total += item.price * 0.8;\n } else if (item.vip) {\n total += item.price * 0.9;\n } else {\n total += item.price;\n }\n }\n return total;\n}", "language": "javascript", "longFunctionThreshold": 8, "nestingThreshold": 2, "duplicateWindow": 4 }

Spot duplicate normalization logic in Python

Detect repeated helper-style functions and confirm duplicate windows across similar code blocks.

{
  "summary": {
    "language": "python",
    "functionCount": 2,
    "duplicateClusters": 1
  },
  "duplicates": [
    {
      "occurrences": 2,
      "lines": [
        1,
        6
      ]
    }
  ]
}
View input parameters
{ "sourceCode": "def normalize_user(row):\n email = row[\"email\"].strip().lower()\n if not email:\n return None\n return {\"email\": email, \"team\": row.get(\"team\", \"general\")}\n\ndef normalize_admin(row):\n email = row[\"email\"].strip().lower()\n if not email:\n return None\n return {\"email\": email, \"team\": row.get(\"team\", \"general\")}", "language": "python", "longFunctionThreshold": 20, "nestingThreshold": 3, "duplicateWindow": 3 }

Key Facts

Category
Development
Input Types
textarea, select, number
Output Type
json
Sample Coverage
4
API Ready
Yes

Overview

Code Complexity Analyzer evaluates source code with practical heuristics for cyclomatic complexity, cognitive complexity, nesting depth, long functions, and repeated logic.

When to Use

  • When you want a quick code quality signal before review or refactoring.
  • When team leads need a lightweight way to spot high-risk functions.
  • When you are comparing maintainability across JavaScript, TypeScript, Python, Java, or Go code.
  • When duplicate logic and deeply nested control flow are slowing down iteration.

How It Works

  • Paste source code and choose a language or let the tool detect it automatically.
  • The analyzer extracts functions or logical blocks using cross-language heuristics.
  • It scores each block for branch count, nesting, and cognitive load.
  • The result includes hotspots, duplicate windows, and concrete refactoring suggestions.

Use Cases

Prioritizing refactors before a release freeze.
Reviewing legacy code to identify maintainability hotspots.
Teaching teams how control flow and nesting affect readability.
Adding lightweight static analysis to an engineering workflow.

Examples

1. Find refactor targets in a legacy service

Tech lead
Background
A backend module has grown for years with many conditional branches and nested logic.
Problem
The team needs to decide which functions should be refactored first.
How to Use
Paste the module code, keep language detection on, and review the hotspot list and duplicate windows.
Example Config
Language: Auto Detect. Long function threshold: 50. Nesting threshold: 4.
Outcome
The team gets a ranked view of risky functions and clear starting points for cleanup.

Try with Samples

development

Related Hubs

FAQ

Is this a full AST-based static analyzer?

No. It uses practical heuristics to provide fast, language-aware signals without requiring heavyweight parsing pipelines.

Which languages are supported?

The tool supports JavaScript, TypeScript, Python, Java, and Go, with automatic detection available.

Can it identify duplicate code?

Yes. It looks for repeated normalized line windows so you can spot likely copy-paste logic.

Does it give improvement advice?

Yes. Each hotspot function can include suggestions such as reducing branching, extracting helpers, or flattening control flow.

API Documentation

Request Endpoint

POST /en/api/tools/code-complexity-analyzer

Request Parameters

Parameter Name Type Required Description
sourceCode textarea Yes -
language select No -
longFunctionThreshold number No -
nestingThreshold number No -
duplicateWindow number No -

Response Format

{
  "key": {...},
  "metadata": {
    "key": "value"
  },
  "error": "Error message (optional)",
  "message": "Notification message (optional)"
}
JSON Data: JSON Data

AI MCP Documentation

Add this tool to your MCP server configuration:

{
  "mcpServers": {
    "elysiatools-code-complexity-analyzer": {
      "name": "code-complexity-analyzer",
      "description": "Measure cyclomatic and cognitive complexity across multiple programming languages",
      "baseUrl": "https://elysiatools.com/mcp/sse?toolId=code-complexity-analyzer",
      "command": "",
      "args": [],
      "env": {},
      "isActive": true,
      "type": "sse"
    }
  }
}

You can chain multiple tools, e.g.: `https://elysiatools.com/mcp/sse?toolId=png-to-webp,jpg-to-webp,gif-to-webp`, max 20 tools.

If you encounter any issues, please contact us at [email protected]