refactor-method-complexity-reduce

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

Updated Aug 28, 2026
One-click install
npx skills add https://github.com/miyake-san/sogo-agent-platform --skill refactor-method-complexity-reduce-miyake-san
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor-method-complexity-reduce
Source: https://github.com/miyake-san/sogo-agent-platform/tree/main/skills/core/refactor-method-complexity-reduce
Command: npx skills add https://github.com/miyake-san/sogo-agent-platform --skill refactor-method-complexity-reduce-miyake-san

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Long methods with deep nesting, chained conditionals, and repeated logic accumulate high cognitive complexity, making code hard to read, test, and maintain. This Skill systematically restructures such methods by extracting helper methods until a target complexity threshold is met. ## Core Features & Use Cases - Complexity Analysis: Identifies sources of cognitive complexity such as nested conditionals, if-else 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 "failed=0" in the output before considering the refactoring complete. - Use Case: A developer has a 200-line order-processing method with a cognitive complexity score of 45. They invoke this Skill with the method name and a threshold of 15, and receive a refactored version with extracted validation and handler methods, verified against the existing test suite. ## Quick Start Refactor the method ProcessOrder to reduce its cognitive complexity to 15 or below by extracting helper methods, then run the tests and confirm zero failures.

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?

Analyze the method to find nested conditionals, repeated blocks, and complex boolean expressions, then extract them into focused helper methods with single responsibilities. Simplify the main method into a high-level flow and verify the complexity metric meets the target threshold.

How to refactor long methods by extracting helper methods?

Extract validation logic into Validate methods, move type-specific processing into handler methods, and create utility methods for repeated operations. Keep helpers static when they do not need instance state, and place them near where they are used.

Does refactoring preserve the original method behavior?

Yes, the refactoring maintains the same input/output behavior, validation, error handling, exception types, and error messages. All parameters are passed correctly to extracted helpers so functionality is unchanged.

Why must tests be verified after refactoring code?

Running tests is not the same as verifying they passed; the output must explicitly show failed=0. If any tests fail, each failure is analyzed for root causes like null handling or condition logic errors, fixed, and re-run until all pass.

What are the limitations of extracting helper methods for complexity?

Extraction reduces measured complexity but does not redesign poor overall architecture or algorithmic inefficiency. It works best when the method has identifiable, separable responsibilities rather than deeply intertwined stateful logic.