Back to Tools

Code Complexity Analyzer

Approximate Cyclomatic Complexity, Nesting Depth, and Function Count.

Input Data

A quick complexity estimate for a code snippet

Code Complexity Analyzer gives you three rough measurements for a block of code: an approximate cyclomatic complexity score, the deepest level of curly-brace nesting, and the number of functions. Cyclomatic complexity counts the independent paths through code, and a high number usually means a function is hard to read, test and change safely. This tool is meant for a fast first look at a snippet, not for replacing a full static-analysis suite.

Getting a reading

  1. Paste JavaScript, PHP or C++-style code into the Input Data box. Press Sample if you want a small example to try, and Clear to reset.
  2. Press Process Now. If the box is empty you will see an error asking for code.
  3. Read the four result tiles: Cyclomatic Complexity, Max Nesting Depth, Total Functions and Maintainability.
  4. Use Copy or Download if you want the text of the result as result.txt.

How the numbers are calculated

Before counting, the tool strips comments and string contents so that a word inside a message does not count. It then adds up the keywords if, for, while, case and catch, each question mark and each && or || operator, and adds one for the entry path. Functions are counted as occurrences of the word function plus arrow symbols. Nesting depth is the highest number of open curly braces at any point. The built-in sample, with an if, a for and another if nested three levels deep, scores a complexity of 4, a depth of 3 and one function.

The Maintainability tile is simple: it shows Good when complexity is 10 or below and High above that, so High is a warning that the code is complex.

Practical uses

  • Checking whether a long function you inherited deserves splitting into smaller ones.
  • Comparing the before and after of a refactor to see whether branching really dropped.
  • Giving students a concrete way to see how extra conditions add paths.
  • Spotting deeply nested blocks during a quick code review.

Limitations worth knowing

This is a text-pattern estimate, not a parser. Indentation-based languages such as Python have no braces, so depth will read as zero. PHP foreach is not matched by the for pattern, and switch, else and do are not counted on their own. Question marks in optional chaining or nullish operators are counted as ternaries, and every function shape other than the function keyword or an arrow is missed. Treat the figures as a guide, and score whole files with caution because the count covers everything you paste.

Related Tools




Frequently Asked Questions

What is cyclomatic complexity?
It is a measure of how many independent paths run through a piece of code. Each decision point, such as an if, loop or case, adds one path. Higher scores generally mean the code needs more tests to cover and is harder to follow.
Which languages does the analyzer support?
The input hint mentions JavaScript, PHP and C++, and it works reasonably on other brace-based languages such as Java or C#. It relies on pattern matching for keywords and curly braces, so languages without braces, like Python, will not produce a meaningful nesting depth.
Why does the Maintainability tile say High?
The tile shows High when the estimated complexity is above 10, and Good when it is 10 or below. Despite the wording, High signals a warning that the code is complex and may be worth simplifying. It is a simple threshold, not a full maintainability index.
Are comments and strings ignored?
Yes, before counting the tool removes block comments, line comments and the contents of quoted strings and template literals. This stops words like if or for inside a comment or message from inflating the score, though unusual formatting can still confuse the pattern matching.
Why does my function count look wrong?
Functions are counted as uses of the word function plus arrow symbols. Class methods without that keyword, PHP or C++ methods written differently, and other syntaxes are not detected, so the count can be lower than the true number. Treat it as an estimate.
Support Chat
We typically reply within minutes

Hello! 👋 Before we start, please tell us your name.