{"id":"eba8a0b2-513b-4c96-9812-9f68f41bd630","shortId":"dbpBaz","kind":"skill","title":"refactor-method-complexity-reduce","tagline":"Refactor given method `${input:methodName}` to reduce its cognitive complexity to `${input:complexityThreshold}` or below, by extracting helper methods.","description":"# Refactor Method to Reduce Cognitive Complexity\n\n## Objective\nRefactor the method `${input:methodName}`, to reduce its cognitive complexity to `${input:complexityThreshold}` or below, by extracting logic into focused helper methods.\n\n## Instructions\n\n1. **Analyze the current method** to identify sources of cognitive complexity:\n   - Nested conditional statements\n   - Multiple if-else or switch chains\n   - Repeated code blocks\n   - Multiple loops with conditions\n   - Complex boolean expressions\n\n2. **Identify extraction opportunities**:\n   - Validation logic that can be extracted into a separate method\n   - Type-specific or case-specific processing that repeats\n   - Complex transformations or calculations\n   - Common patterns that appear multiple times\n\n3. **Extract focused helper methods**:\n   - Each helper should have a single, clear responsibility\n   - Extract validation into separate `Validate*` methods\n   - Extract type-specific logic into handler methods\n   - Create utility methods for common operations\n   - Use appropriate access levels (static, private, async)\n\n4. **Simplify the main method**:\n   - Reduce nesting depth\n   - Replace massive if-else chains with smaller orchestrated calls\n   - Use switch statements where appropriate for cleaner dispatch\n   - Ensure the main method reads as a high-level flow\n\n5. **Preserve functionality**:\n   - Maintain the same input/output behavior\n   - Keep all validation and error handling\n   - Preserve exception types and error messages\n   - Ensure all parameters are properly passed to helpers\n\n6. **Best practices**:\n   - Make helper methods static when they don't need instance state\n   - Use null checks and guard clauses early\n   - Avoid creating unnecessary local variables\n   - Consider using tuples for multiple return values\n   - Group related helper methods together\n\n## Implementation Approach\n\n- Extract helper methods before refactoring the main flow\n- Test incrementally to ensure no regressions\n- Use meaningful names that describe the extracted responsibility\n- Keep extracted methods close to where they're used\n- Consider making repeated code patterns into generic methods\n\n## Result\n\nThe refactored method should:\n- Have cognitive complexity reduced to the target threshold of `${input:complexityThreshold}` or below\n- Be more readable and maintainable\n- Have clear separation of concerns\n- Be easier to test and debug\n- Retain all original functionality\n\n## Testing and Validation\n\n**CRITICAL: After completing the refactoring, you MUST:**\n\n1. **Run all existing tests** related to the refactored method and its surrounding functionality\n2. **MANDATORY: Explicitly verify test results show \"failed=0\"**\n   - **NEVER assume tests passed** - always examine the actual test output\n   - Search for the summary line containing pass/fail counts (e.g., \"passed=X failed=Y\")\n   - **If the summary shows any number other than \"failed=0\", tests have FAILED**\n   - If test output is in a file, read the entire file to locate and verify the failure count\n   - Running tests is NOT the same as verifying tests passed\n   - **Do not proceed** until you have explicitly confirmed zero failures\n3. **If any tests fail (failed > 0):**\n   - State clearly how many tests failed\n   - Analyze each failure to understand what functionality was broken\n   - Common causes: null handling, empty collection checks, condition logic errors\n   - Identify the root cause in the refactored code\n   - Correct the refactored code to restore the original behavior\n   - Re-run tests and verify \"failed=0\" in the output\n   - Repeat until all tests pass (failed=0)\n4. **Verify compilation** - Ensure there are no compilation errors\n5. **Check cognitive complexity** - Confirm the metric is at or below the target threshold of `${input:complexityThreshold}`\n\n## Confirmation Checklist\n- [ ] Code compiles without errors\n- [ ] **Test results explicitly state \"failed=0\"** (verified by reading the output)\n- [ ] All test failures analyzed and corrected (if any occurred)\n- [ ] Cognitive complexity is at or below the target threshold of `${input:complexityThreshold}`\n- [ ] All original functionality is preserved\n- [ ] Code follows project conventions and standards","tags":["refactor","method","complexity","reduce","awesome","copilot","github","agent-skills","agents","custom-agents","github-copilot","hacktoberfest"],"capabilities":["skill","source-github","skill-refactor-method-complexity-reduce","topic-agent-skills","topic-agents","topic-awesome","topic-custom-agents","topic-github-copilot","topic-hacktoberfest","topic-prompt-engineering"],"categories":["awesome-copilot"],"synonyms":[],"warnings":[],"endpointUrl":"https://skills.sh/github/awesome-copilot/refactor-method-complexity-reduce","protocol":"skill","transport":"skills-sh","auth":{"type":"none","details":{"cli":"npx skills add github/awesome-copilot","source_repo":"https://github.com/github/awesome-copilot","install_from":"skills.sh"}},"qualityScore":"0.700","qualityRationale":"deterministic score 0.70 from registry signals: · indexed on github topic:agent-skills · 33270 github stars · SKILL.md body (4,212 chars)","verified":false,"liveness":"unknown","lastLivenessCheck":null,"agentReviews":{"count":0,"score_avg":null,"cost_usd_avg":null,"success_rate":null,"latency_p50_ms":null,"narrative_summary":null,"summary_updated_at":null},"enrichmentModel":"deterministic:skill-github:v1","enrichmentVersion":1,"enrichedAt":"2026-05-18T18:52:23.537Z","embedding":null,"createdAt":"2026-04-18T20:25:41.995Z","updatedAt":"2026-05-18T18:52:23.537Z","lastSeenAt":"2026-05-18T18:52:23.537Z","tsv":"'0':374,407,455,505,515,553 '1':55,352 '2':86,366 '3':120,449 '4':160,516 '5':197,525 '6':225 'access':155 'actual':382 'alway':379 'analyz':56,462,562 'appear':117 'approach':264 'appropri':154,182 'assum':376 'async':159 'avoid':246 'behavior':204,497 'best':226 'block':78 'boolean':84 'broken':470 'calcul':113 'call':177 'case':105 'case-specif':104 'caus':472,484 'chain':75,173 'check':241,477,526 'checklist':543 'claus':244 'cleaner':184 'clear':131,328,457 'close':290 'code':77,299,488,492,544,585 'cognit':14,29,40,64,310,527,568 'collect':476 'common':114,151,471 'compil':518,523,545 'complet':347 'complex':4,15,30,41,65,83,110,311,528,569 'complexitythreshold':18,44,319,541,579 'concern':331 'condit':67,82,478 'confirm':446,529,542 'consid':251,296 'contain':390 'convent':588 'correct':489,564 'count':392,428 'creat':147,247 'critic':345 'current':58 'debug':337 'depth':167 'describ':283 'dispatch':185 'e.g':393 'earli':245 'easier':333 'els':72,172 'empti':475 'ensur':186,217,276,519 'entir':420 'error':209,215,480,524,547 'examin':380 'except':212 'exist':355 'explicit':368,445,550 'express':85 'extract':22,48,88,95,121,133,139,265,285,288 'fail':373,396,406,410,453,454,461,504,514,552 'failur':427,448,464,561 'file':417,421 'flow':196,272 'focus':51,122 'follow':586 'function':199,341,365,468,582 'generic':302 'given':7 'group':258 'guard':243 'handl':210,474 'handler':145 'helper':23,52,123,126,224,229,260,266 'high':194 'high-level':193 'identifi':61,87,481 'if-els':70,170 'implement':263 'increment':274 'input':9,17,35,43,318,540,578 'input/output':203 'instanc':237 'instruct':54 'keep':205,287 'level':156,195 'line':389 'local':249 'locat':423 'logic':49,91,143,479 'loop':80 'main':163,188,271 'maintain':200,326 'make':228,297 'mandatori':367 'mani':459 'massiv':169 'meaning':280 'messag':216 'method':3,8,24,26,34,53,59,99,124,138,146,149,164,189,230,261,267,289,303,307,361 'methodnam':10,36 'metric':531 'multipl':69,79,118,255 'must':351 'name':281 'need':236 'nest':66,166 'never':375 'null':240,473 'number':403 'object':31 'occur':567 'oper':152 'opportun':89 'orchestr':176 'origin':340,496,581 'output':384,413,508,558 'paramet':219 'pass':222,378,394,438,513 'pass/fail':391 'pattern':115,300 'practic':227 'preserv':198,211,584 'privat':158 'proceed':441 'process':107 'project':587 'proper':221 're':294,499 're-run':498 'read':190,418,556 'readabl':324 'reduc':5,12,28,38,165,312 'refactor':2,6,25,32,269,306,349,360,487,491 'refactor-method-complexity-reduc':1 'regress':278 'relat':259,357 'repeat':76,109,298,509 'replac':168 'respons':132,286 'restor':494 'result':304,371,549 'retain':338 'return':256 'root':483 'run':353,429,500 'search':385 'separ':98,136,329 'show':372,401 'simplifi':161 'singl':130 'skill' 'skill-refactor-method-complexity-reduce' 'smaller':175 'sourc':62 'source-github' 'specif':102,106,142 'standard':590 'state':238,456,551 'statement':68,180 'static':157,231 'summari':388,400 'surround':364 'switch':74,179 'target':315,537,575 'test':273,335,342,356,370,377,383,408,412,430,437,452,460,501,512,548,560 'threshold':316,538,576 'time':119 'togeth':262 'topic-agent-skills' 'topic-agents' 'topic-awesome' 'topic-custom-agents' 'topic-github-copilot' 'topic-hacktoberfest' 'topic-prompt-engineering' 'transform':111 'tupl':253 'type':101,141,213 'type-specif':100,140 'understand':466 'unnecessari':248 'use':153,178,239,252,279,295 'util':148 'valid':90,134,137,207,344 'valu':257 'variabl':250 'verifi':369,425,436,503,517,554 'without':546 'x':395 'y':397 'zero':447","prices":[{"id":"a2755f17-2bf7-4b1c-b5d5-74e2bcbf18e8","listingId":"eba8a0b2-513b-4c96-9812-9f68f41bd630","amountUsd":"0","unit":"free","nativeCurrency":null,"nativeAmount":null,"chain":null,"payTo":null,"paymentMethod":"skill-free","isPrimary":true,"details":{"org":"github","category":"awesome-copilot","install_from":"skills.sh"},"createdAt":"2026-04-18T20:25:41.995Z"}],"sources":[{"listingId":"eba8a0b2-513b-4c96-9812-9f68f41bd630","source":"github","sourceId":"github/awesome-copilot/refactor-method-complexity-reduce","sourceUrl":"https://github.com/github/awesome-copilot/tree/main/skills/refactor-method-complexity-reduce","isPrimary":false,"firstSeenAt":"2026-04-18T21:51:01.207Z","lastSeenAt":"2026-05-18T18:52:23.537Z"},{"listingId":"eba8a0b2-513b-4c96-9812-9f68f41bd630","source":"skills_sh","sourceId":"github/awesome-copilot/refactor-method-complexity-reduce","sourceUrl":"https://skills.sh/github/awesome-copilot/refactor-method-complexity-reduce","isPrimary":true,"firstSeenAt":"2026-04-18T20:25:41.995Z","lastSeenAt":"2026-05-07T22:40:17.755Z"}],"details":{"listingId":"eba8a0b2-513b-4c96-9812-9f68f41bd630","quickStartSnippet":null,"exampleRequest":null,"exampleResponse":null,"schema":null,"openapiUrl":null,"agentsTxtUrl":null,"citations":[],"useCases":[],"bestFor":[],"notFor":[],"kindDetails":{"org":"github","slug":"refactor-method-complexity-reduce","github":{"repo":"github/awesome-copilot","stars":33270,"topics":["agent-skills","agents","ai","awesome","custom-agents","github-copilot","hacktoberfest","prompt-engineering"],"license":"mit","html_url":"https://github.com/github/awesome-copilot","pushed_at":"2026-05-18T01:26:59Z","description":"Community-contributed instructions, agents, skills, and configurations to help you make the most of GitHub Copilot.","skill_md_sha":"46f0700f595686797dcefc0e1c0143a66da2e67d","skill_md_path":"skills/refactor-method-complexity-reduce/SKILL.md","default_branch":"main","skill_tree_url":"https://github.com/github/awesome-copilot/tree/main/skills/refactor-method-complexity-reduce"},"layout":"multi","source":"github","category":"awesome-copilot","frontmatter":{"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."},"skills_sh_url":"https://skills.sh/github/awesome-copilot/refactor-method-complexity-reduce"},"updatedAt":"2026-05-18T18:52:23.537Z"}}