Home / Market / refactor method complexity reduce

refactor method complexity reduce

Refactor given method `${input:methodName}` to reduce its cognitive complexity to `${input:complexityThreshold}` or below, by extracting helper methods.

skill★ 4179410040 dlskills.shMITInstall in CosmosUpstream Source

Documentation & Preview

--- name: refactor-method-complexity-reduce description: 'Refactor given method ${input:methodName} to reduce its cognitive complexity to ${input:complexityThreshold} or below, by extracting helper methods.'

---

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

  1. Analyze the current method to identify sources of cognitive complexity:
  1. Identify extraction opportunities:
  1. Extract focused helper methods:
  1. Simplify the main method:
  1. Preserve functionality:
  1. Best practices:

Implementation Approach

Result

The refactored method should:

Testing and Validation

CRITICAL: After completing the refactoring, you MUST:

  1. Run all existing tests related to the refactored method and its surrounding functionality
  2. MANDATORY: Explicitly verify test results show "failed=0"
  1. If any tests fail (failed > 0):
  1. Verify compilation - Ensure there are no compilation errors
  2. Check cognitive complexity - Confirm the metric is at or below the target threshold of ${input:complexityThreshold}

Confirmation Checklist