# complexity-analyzer > Analyze C# code complexity to identify methods that need testing. Use when you need to understand code complexity or prioritize testing efforts. (project, gitignored) - Author: Claude - Repository: psklarkins/claude-tools - Version: 20260108102420 - Stars: 0 - Forks: 0 - Last Updated: 2026-02-06 - Source: https://github.com/psklarkins/claude-tools - Web: https://mule.run/skillshub/@@psklarkins/claude-tools~complexity-analyzer:20260108102420 --- --- name: complexity-analyzer description: Analyze C# code complexity to identify methods that need testing. Use when you need to understand code complexity or prioritize testing efforts. (project, gitignored) --- # Code Complexity Analyzer Skill This skill analyzes C# code to calculate cyclomatic complexity and identify which methods need testing most urgently. **Tool Location:** `C:\Users\Administrator\.claude\skills\complexity-analyzer\complexity-analyzer.exe` ## When to Use This Skill - Before writing tests - to identify which methods to prioritize - During code review - to find overly complex methods - When refactoring - to understand current complexity - When asked "which methods need testing?" - When asked "what's the complexity of this code?" - When asked to analyze complexity by namespace, project, directory, or class ## What This Skill Does 1. **Calculates cyclomatic complexity** for each method in a C# file or directory 2. **Prioritizes methods** based on complexity (CRITICAL > 15, HIGH > 10, MEDIUM > 5, LOW ≤ 5) 3. **Groups results** by namespace, project, directory, or class 4. **Identifies testable methods** (complexity > 1) 5. **Excludes trivial methods** (auto-properties, simple constructors) 6. **Generates priority report** for testing efforts ## Commands ```bash # Analyze via claude-tools CLI claude-tools skill complexity-analyzer # Or run executable directly C:\Users\Administrator\.claude\skills\complexity-analyzer\complexity-analyzer.exe ``` ## How Complexity is Calculated Cyclomatic complexity counts decision points in code: - Base complexity: 1 - Each `if` statement: +1 - Each `while`/`for`/`foreach` loop: +1 - Each `switch` case: +1 - Each `catch` clause: +1 - Each ternary operator `? :`: +1 - Each `&&` or `||` operator: +1 **Example:** ```csharp public bool ValidateOrder(Order order) // Complexity = 4 { if (order == null) // +1 return false; if (order.Items.Count == 0) // +1 return false; if (order.Total < 0) // +1 return false; return true; } ``` ## Priority Levels - **CRITICAL** (complexity > 15): Must have comprehensive tests - **HIGH** (complexity > 10): Should have thorough tests - **MEDIUM** (complexity > 5): Needs basic test coverage - **LOW** (complexity ≤ 5): Simple tests sufficient ## Workflow When this skill is invoked: 1. **Determine scope**: single file or directory? 2. **Choose grouping**: by-namespace (default), by-project, by-directory, or by-class 3. **Run the ComplexityAnalyzer tool** with appropriate arguments 4. **Parse and present results** showing: - Area-based summary (namespace/project/directory/class) - Average and max complexity per area - Critical/High/Medium method counts - Hottest areas needing attention 5. **Recommend** which areas/methods to test first ## Output Formats ### Single File ``` === CODE COMPLEXITY ANALYSIS === Total Methods: 15 Need Testing: 12 Can Skip: 3 PRIORITY METHODS FOR TESTING: Priority Complexity Lines Method Class -------------------------------------------------------------------------------- CRITICAL 18 45 ProcessPayment OrderService HIGH 12 32 ValidateInventory OrderService ``` ### By Namespace (Directory) ``` === COMPLEXITY BY NAMESPACE === Area Methods Avg Max Critical High Medium MyApp.Core.Services 45 6.2 21 2 8 12 MyApp.Api.Controllers 32 4.8 15 0 3 8 MyApp.Data.Repositories 28 3.5 12 0 1 6 === SUMMARY === Hottest Area: MyApp.Core.Services Average Complexity: 6.2 Max Complexity: 21 Critical Methods: 2 ⚠️ AREAS NEEDING ATTENTION: MyApp.Core.Services - 2 CRITICAL priority methods - 8 HIGH priority methods ``` ## Integration with Test Generation After running complexity analysis, you can: 1. Use the report to prioritize testing 2. Invoke the `dotnet-test-automation` skill for high-priority methods 3. Focus testing efforts on CRITICAL and HIGH complexity methods 4. Use area analysis to identify which namespaces/projects need refactoring ## Example Usage User asks: - "Analyze the complexity of ProductService.cs" - "Which methods in OrderProcessor.cs need testing?" - "Show me the most complex methods in this file" - "What's the complexity score for this code?" - "Analyze complexity by namespace for the src directory" - "Which project has the highest complexity?" Skill will: 1. Determine appropriate scope and grouping 2. Run the RoslynTools.ComplexityAnalyzer 3. Generate priority report 4. Suggest which methods/areas to test first ## Decision Rules **Exclude from analysis:** - Auto-properties (no logic) - Simple field assignments - Properties with only get/set - Files in obj/ and bin/ directories **Include in analysis:** - All methods with logic - Properties with computed values - Constructors with logic **Methods with complexity = 1:** - Still listed but marked as "Can Skip" - Usually trivial and don't need explicit tests - Tested indirectly through other methods ## Notes - This skill uses Roslyn for parsing, so it understands C# syntax perfectly - Works with modern C# features (records, pattern matching, etc.) - Can analyze entire solutions or specific directories - Automatically excludes obj/ and bin/ folders - Fast analysis using syntax trees (no compilation required) - Output can be saved as JSON for programmatic use ## Follow-up Actions After analysis, suggest: 1. "Generate tests for the CRITICAL priority methods" 2. "Let's refactor methods with complexity > 15" 3. "Run the test-coverage skill to see current coverage" 4. "Analyze the hottest namespace/project in more detail"