nmbl Documentation
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage
Edit page

cc - Cyclomatic Complexity

Overview

The cc command calculates cyclomatic complexity for C# methods in your projects or directories. Cyclomatic complexity counts the number of linearly independent paths through a method. A score of 1 means a single path with no branches; higher scores indicate more conditional logic and typically correlate with harder-to-test code.

Syntax

nmbl cc <ProjectFileOrDirectory>

Arguments

  • ProjectFileOrDirectory - Path to a .csproj file, a project directory, or . for the current directory.

Output

Prints the count of files being analyzed, then displays a rounded table of the top 10 methods ranked by cyclomatic complexity (highest first), followed by the total number of methods analyzed.

Analyzing 42 C# file(s)...

Top 10 methods by cyclomatic complexity:

╭──────────────────────────────────────────────────────────────╮────────────╮
│ Method                                                       │ Complexity │
├──────────────────────────────────────────────────────────────┼────────────┤
│ MyNamespace.OrderProcessor.ProcessOrder(Order)               │         25 │
│ MyNamespace.ReportGenerator.GenerateReport(int, bool)        │         18 │
╰──────────────────────────────────────────────────────────────╯────────────╯

Total methods analyzed: 128

Exit Codes

  • 0 - Success, including when no C# files or methods are found.
  • 1 - The required path argument is missing or an unexpected error occurs.

Examples

Analyze a specific project

nmbl cc src/MyProject/MyProject.csproj

Calculates complexity for all methods in the specified project.

Analyze all C# files in a directory

nmbl cc src/

Recursively analyzes all C# files in the directory tree.

Analyze the current directory

nmbl cc .

Analyzes all C# files in the current directory and subdirectories.

Understanding the Results

Methods with higher cyclomatic complexity scores are generally:

  • Harder to understand and reason about
  • More difficult to write thorough tests for
  • More prone to defects
  • Good candidates for refactoring

Complexity guidelines:

  • 1–10: Simple, easy to understand
  • 11–20: Moderate complexity, consider refactoring
  • 21–50: High complexity, should be refactored
  • 50+: Very high complexity, critical to refactor

Industry guidelines commonly flag methods above 10 as candidates for refactoring.

  • ac - Calculate aggregate complexity across a project
  • cogc - Calculate cognitive complexity
  • regions - Count region directives
  • todos - Find TODO comments