refactor-method-complexity-reduce

Refactors a method to reduce cognitive complexity by extracting helper methods.

1|1|Updated Jan 29, 2026
One-click install
npx skills add https://github.com/ultraviollettnympho/transit-ticket --skill refactor-method-complexity-reduce-ultraviollettnympho
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor-method-complexity-reduce
Source: https://github.com/ultraviollettnympho/transit-ticket/tree/main/.github/skills/refactor-method-complexity-reduce
Command: npx skills add https://github.com/ultraviollettnympho/transit-ticket --skill refactor-method-complexity-reduce-ultraviollettnympho

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Methods with high cognitive complexity—deep nesting, long if-else chains, and repeated logic—are hard to read, test, and maintain. This Skill guides an AI through a structured refactoring process that lowers a method's cognitive complexity to a target threshold without changing its behavior. ## Core Features & Use Cases - Complexity Analysis: Identifies sources of cognitive complexity such as nested conditionals, switch chains, repeated blocks, and complex boolean expressions. - Helper Method Extraction: Extracts validation, type-specific handling, and common operations into focused single-responsibility helper methods. - Mandatory Test Verification: Requires running existing tests and explicitly confirming a "failed=0" result before considering the refactoring complete. - Use Case: A developer has a 200-line method flagged by a linter for a cognitive complexity of 35. They invoke this Skill with the method name and a threshold of 15, and receive a refactored version with extracted helpers, verified against the existing test suite. ## Quick Start Ask the AI to refactor the method ProcessOrder to reduce its cognitive complexity to 10 or below by extracting helper methods.

Frequently Asked Questions about refactor-method-complexity-reduce

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I reduce cognitive complexity of a method?

Reduce cognitive complexity by extracting nested conditionals, repeated blocks, and type-specific logic into focused helper methods with single responsibilities. This Skill guides that extraction while preserving the original input/output behavior and error handling.

How to refactor a long method without breaking existing tests?

Extract helper methods incrementally, then run the full existing test suite after each change. This Skill mandates verifying the test output explicitly shows zero failures before the refactoring is considered complete.

What causes high cognitive complexity in code?

High cognitive complexity comes from nested conditional statements, long if-else or switch chains, multiple loops with conditions, repeated code blocks, and complex boolean expressions. These structures increase the mental effort needed to follow the control flow.

Does refactoring change the method's behavior or error handling?

No. The refactoring preserves the same input/output behavior, validation logic, exception types, and error messages. Only the internal structure changes, with logic moved into well-named helper methods.

When should I not extract helper methods during refactoring?

Avoid extraction when it would create unnecessary indirection for trivially simple logic or when the method is already below the target complexity threshold. Extraction is most valuable for repeated patterns, validation blocks, and case-specific processing.