github avatar

Refactor Method Complexity Reduce

The refactor-method-complexity-reduce skill analyzes a specified method to identify sources of cognitive complexity—such as nested conditionals, repeated code, and complex logic—and refactors it by extracting focused helper methods until the complexity falls below a target threshold. It is designed for developers who need to improve code maintainability and readability by reducing method complexity while preserving all original functionality and passing existing tests. The skill solves the problem of overly complex methods that are difficult to understand, test, and modify by systematically breaking them into smaller, single-responsibility helper methods.

skills.sh installs
10K
GitHub stars
41K
last updated
Aug 21, 2026

Install

$ npx -y skills add github/awesome-copilot --skill refactor-method-complexity-reduce --agent claude-code

Installs into .claude/skills of the current project.

Files

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:

    • Nested conditional statements
    • Multiple if-else or switch chains
    • Repeated code blocks
    • Multiple loops with conditions
    • Complex boolean expressions
  2. 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
  3. Extract focused helper methods:

    • Each helper should have a single, clear responsibility
    • Extract validation into separate Validate* methods
    • Extract type-specific logic into handler methods
    • Create utility methods for common operations
    • Use appropriate access levels (static, private, async)

Sponsors

Details

Repository
github.com/github/awesome-copilot
Categories
Git & Pull Requests, Code Review & Quality, AI & Agent Building

More from github/awesome-copilot

All 318
1github avatarpowerbi-modelinggithub/awesome-copilotPower BI semantic modeling assistant for building optimized data models. Use when working with Power BI semantic models, creating measures, designing star schem10Kskills.sh installs
2github avatarscoutqa-testgithub/awesome-copilotThis skill should be used when the user asks to "test this website", "run exploratory testing", "check for accessibility issues", "verify the login flow works",10Kskills.sh installs
3github avatarnano-banana-pro-openroutergithub/awesome-copilotGenerate or edit images via OpenRouter with the Gemini 3 Pro Image model. Use for prompt-only image generation, image edits, and multi-image compositing; suppor10Kskills.sh installs
4github avatarmarkdown-to-htmlgithub/awesome-copilotConvert Markdown files to HTML similar to `marked.js`, `pandoc`, `gomarkdown/markdown`, or similar tools; or writing custom script to convert markdown to html a9.9Kskills.sh installs
5github avatarmeeting-minutesgithub/awesome-copilotGenerate concise, actionable meeting minutes for internal meetings. Includes metadata, attendees, agenda, decisions, action items (owner + due date), and follow9.9Kskills.sh installs
6github avatardataverse-python-production-codegithub/awesome-copilotGenerate production-ready Python code using Dataverse SDK with error handling, optimization, and best practices9.8Kskills.sh installs