Rebel.Alliance.ObjectInfo.DeepDive.CyclomaticComplexityAnalyzer 1.0.1

dotnet add package Rebel.Alliance.ObjectInfo.DeepDive.CyclomaticComplexityAnalyzer --version 1.0.1                
NuGet\Install-Package Rebel.Alliance.ObjectInfo.DeepDive.CyclomaticComplexityAnalyzer -Version 1.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Rebel.Alliance.ObjectInfo.DeepDive.CyclomaticComplexityAnalyzer" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Rebel.Alliance.ObjectInfo.DeepDive.CyclomaticComplexityAnalyzer --version 1.0.1                
#r "nuget: Rebel.Alliance.ObjectInfo.DeepDive.CyclomaticComplexityAnalyzer, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Rebel.Alliance.ObjectInfo.DeepDive.CyclomaticComplexityAnalyzer as a Cake Addin
#addin nuget:?package=Rebel.Alliance.ObjectInfo.DeepDive.CyclomaticComplexityAnalyzer&version=1.0.1

// Install Rebel.Alliance.ObjectInfo.DeepDive.CyclomaticComplexityAnalyzer as a Cake Tool
#tool nuget:?package=Rebel.Alliance.ObjectInfo.DeepDive.CyclomaticComplexityAnalyzer&version=1.0.1                

CyclomaticComplexityAnalyzer

The CyclomaticComplexityAnalyzer is a plugin for ObjectInfo.Deepdive that calculates the cyclomatic complexity of methods in a .NET application.

Key Features

  • Implements the IMethodAnalyzer interface
  • Calculates cyclomatic complexity for individual methods
  • Provides interpretation of the calculated complexity

Implementation Details

The analyzer uses the following technique to parse and interpret the method body:

  1. Method Body Retrieval:

    • Uses reflection to find the method in the loaded assemblies
    • Retrieves the method body as a byte array using MethodBody.GetILAsByteArray()
  2. Complexity Calculation:

    • Converts the byte array to a string representation
    • Counts the number of branch instructions (represented by the byte 0x02 in IL)
    • Adds 1 to the count to get the final complexity

Complexity Interpretation

The analyzer provides the following interpretation of cyclomatic complexity:

  • 1-5: Simple, low-risk code
  • 6-10: Moderately complex, moderate risk
  • 11-20: Complex, high-risk code
  • 21+: Untestable code (very high risk)

Integration with ObjectInfo.Deepdive

  • Implements the IAnalyzerPlugin interface for easy integration
  • Can be loaded dynamically by the PluginLoader

Limitations

  • The current implementation may not capture all nuances of cyclomatic complexity
  • Relies on IL code analysis, which may not always accurately represent source code complexity

The CyclomaticComplexityAnalyzer provides valuable insights into method complexity, helping developers identify areas of code that may need refactoring or additional testing.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 86 9/21/2024
1.0.0 85 9/21/2024