General
73 installs
Refactor Method to Reduce Cognitive Complexity
by github/awesome-copilot
Refactor given method `${input:methodName}` to reduce its cognitive complexity to `${input:complexityThreshold}` or below, by extracting helper methods.
Skill content
Refactor a method to reduce cognitive complexity by extracting helper methods.
- Analyzes nested conditionals, loops, and complex boolean expressions to identify refactoring opportunities
- Extracts validation logic, type-specific processing, and repeated code blocks into focused helper methods
- Simplifies the main method flow while preserving all original functionality and error handling
- Includes mandatory test verification to confirm zero test failures and cognitive complexity at or below the target threshold
Refactor Method to Reduce Cognitive Complexity
Objective
Refactor the method ${input:methodName}, to reduce its cognitive complexity to ${input:complexityThreshold} or below, by extracting logic into focused helper methods.
Instructions
-
Analyze the current method to identify sources of cognitive complexity:
- Nested conditional statements
- Multiple if-else or switch chains
- Repeated code blocks
- Multiple loops with conditions
- Complex boolean expressions
-
Identify extraction opportunities:
- Validation logic that can be extracted into a separate method
- Type-specific or case-specific processing that repeats
- Complex transformations or calculations
- Common patterns that appear multiple times