Code Complexity Analyzer

Paste JavaScript, Python, or PHP into the editor. You get cyclomatic complexity for the whole snippet, nesting depth, function count, and a per-function table so refactoring starts on the worst branch pile, not the shortest file.

Source snippet

Whole-file regex counts. Paste one function for a focused score, or a full module to see which function owns the branches.

Lines0Functions0

Scores

Thresholds follow common Sonar-style bands. Your team policy might differ.

Cyclomatic complexity0Not analyzed
Lines of code0Non-empty lines
Functions0Detected declarations
Nesting depth0Max brace depth
Quality bands
MaintainabilityUnknown
Branch ratingUnknown
Change riskUnknown

Per-function breakdown

Paste code above, then run Analyze. Function-level cyclomatic scores appear here.

Regex, not a compiler

Counts come from pattern matching on if, for, case, &&, ternary operators, and similar tokens. Minified bundles, JSX inside strings, or macros fool the counter. For CI gates on a whole repo, run ESLint complexity, SonarQube, or lizard instead. This page fits a quick paste during code review.

Pull request open. Reviewer asks whether the new handler is too branchy. You scroll three hundred lines, lose count of nested else if chains, approve anyway. Two weeks later a bug hides in branch fourteen.

Cyclomatic complexity turns branch piles into one integer. Higher number means more independent paths through the function. Test coverage tools care because each path wants an assertion.

What the counter adds up

Classic formula starts at one, then adds a point for each decision point McCabe counted in 1976.

if / else
Each branch arm counts. A lone else without a matching if in the same function still registers.
Loops
for, while, do loops each add one. Nested loops stack fast on nesting depth too.
switch / case
Switch header plus each case label. Default counts like any other case.
Ternary & logic
? chains and && / || in conditions. String literals with question marks do not count here unless the regex misreads them.
try / catch
Exception paths add branches the same way guard clauses do.
Nesting depth
Separate metric. Tracks brace depth, not branch count. A flat series of ten if statements scores high on cyclomatic complexity but low on nesting.

Three bands teams still cite in review

ScoreTypical labelWhat reviewers sayWeak spot
1–10LowMerge without debate. Few paths, easy unit tests.Score ignores length. Ten one-liner guards still land in this band.
11–20ModerateAsk for a split or extract helper before merge.Policy varies. Some teams cap at 15, others at 25.
21+HighRefactor required. Risk of untested paths rises.Legacy switch statements on enums hit 40 without feeling unreadable to the author.

The quality badges on the workbench use these bands for maintainability, branch rating, and change risk. Swap the numbers in your linter config if your org document names different ceilings.

Per-function table vs whole-file score

The hero number sums every decision point in the pasted buffer. The breakdown table walks function declarations found by regex, then scores each body separately.

Arrow functions assigned mid-file, class methods without the function keyword, or Python decorators sometimes miss the detector. Paste suspicious blocks alone when the table shows zero functions but the file score looks high.

Where to go next on Toolexe

The Code Maintainability Index page blends Halstead volume, comment ratio, and cyclomatic complexity into a single 0–100 score. Use both when a function scores low on branches but still feels hard to read.

Duplicate logic inflates scores across files. Run the Code Duplication Detector on the same module before you extract helpers.

Branch count does not catch smell patterns. Pair numbers from here with the Code Smell Detector when naming, coupling, or god-class warnings matter more than raw if count.

Performance hotspots hide elsewhere. The Code Performance Analyzer looks at loop cost and synchronous work, not decision trees.

For debt spreadsheets and sprint planning, the Technical Debt Analyzer aggregates broader heuristics. Complexity rows from this tool feed those conversations.

Privacy: Analysis runs in your browser. Snippets never upload to Toolexe servers.

Questions about cyclomatic scores here

Answers tied to this paste-in analyzer, not general static-analysis theory.

Does a low score guarantee clean code?

No. A twenty-line function with one branch scores 2 but might hide a SQL injection or a misspelled API field. Complexity only measures paths, not correctness or naming.

Why does my minified bundle show hundreds?

Minifiers strip newlines but leave every ternary and short-circuit operator. Regex counts each one. Paste formatted source, or point CI at a linter rule instead.

How are individual functions detected?

JavaScript matches function declarations, arrow functions, and simple method shapes. Python looks for def lines. PHP looks for function keywords. Nested inner functions appear as separate rows when the pattern matches.

Does nesting depth equal cyclomatic complexity?

No. Depth only measures how many braces or blocks sit inside each other. Ten sequential if statements without nesting still yield depth 1 but cyclomatic complexity 11.

Which languages get accurate syntax colors?

The Syntax dropdown sets ACE modes for JavaScript, Python, and PHP. Other languages still analyze if keywords resemble C-style syntax, but highlighting often looks wrong without the right mode.

Should I gate merges on this page alone?

Use repo-wide tooling for gates. This analyzer fits ad-hoc review, teaching, or comparing two versions of one function before you open a formal complexity ticket.