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
<PackageReference Include="Rebel.Alliance.ObjectInfo.DeepDive.CyclomaticComplexityAnalyzer" Version="1.0.1" />
paket add Rebel.Alliance.ObjectInfo.DeepDive.CyclomaticComplexityAnalyzer --version 1.0.1
#r "nuget: Rebel.Alliance.ObjectInfo.DeepDive.CyclomaticComplexityAnalyzer, 1.0.1"
// 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:
Method Body Retrieval:
- Uses reflection to find the method in the loaded assemblies
- Retrieves the method body as a byte array using
MethodBody.GetILAsByteArray()
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 | Versions 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. |
-
net8.0
- Rebel.Alliance.ObjectInfo.DeepDive (>= 1.0.0)
- Serilog (>= 4.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.