{"id":"eba8a0b2-513b-4c96-9812-9f68f41bd630","shortId":"dbpBaz","kind":"skill","title":"Refactor Method Complexity Reduce","tagline":"Awesome Copilot skill by Github","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"],"capabilities":["skill","source-github","category-awesome-copilot"],"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":{"install_from":"skills.sh"}},"qualityScore":"0.300","qualityRationale":"deterministic score 0.30 from registry signals: · indexed on skills.sh · published under github/awesome-copilot","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:v1","enrichmentVersion":1,"enrichedAt":"2026-04-22T16:40:17.526Z","embedding":null,"createdAt":"2026-04-18T20:25:41.995Z","updatedAt":"2026-04-22T16:40:17.526Z","lastSeenAt":"2026-04-22T16:40:17.526Z","tsv":"'0':359,392,440,490,500,538 '1':40,337 '2':71,351 '3':105,434 '4':145,501 '5':182,510 '6':210 'access':140 'actual':367 'alway':364 'analyz':41,447,547 'appear':102 'approach':249 'appropri':139,167 'assum':361 'async':144 'avoid':231 'awesom':5 'behavior':189,482 'best':211 'block':63 'boolean':69 'broken':455 'calcul':98 'call':162 'case':90 'case-specif':89 'category-awesome-copilot' 'caus':457,469 'chain':60,158 'check':226,462,511 'checklist':528 'claus':229 'cleaner':169 'clear':116,313,442 'close':275 'code':62,284,473,477,529,570 'cognit':14,25,49,295,512,553 'collect':461 'common':99,136,456 'compil':503,508,530 'complet':332 'complex':3,15,26,50,68,95,296,513,554 'complexitythreshold':29,304,526,564 'concern':316 'condit':52,67,463 'confirm':431,514,527 'consid':236,281 'contain':375 'convent':573 'copilot':6 'correct':474,549 'count':377,413 'creat':132,232 'critic':330 'current':43 'debug':322 'depth':152 'describ':268 'dispatch':170 'e.g':378 'earli':230 'easier':318 'els':57,157 'empti':460 'ensur':171,202,261,504 'entir':405 'error':194,200,465,509,532 'examin':365 'except':197 'exist':340 'explicit':353,430,535 'express':70 'extract':33,73,80,106,118,124,250,270,273 'fail':358,381,391,395,438,439,446,489,499,537 'failur':412,433,449,546 'file':402,406 'flow':181,257 'focus':36,107 'follow':571 'function':184,326,350,453,567 'generic':287 'github':9 'group':243 'guard':228 'handl':195,459 'handler':130 'helper':37,108,111,209,214,245,251 'high':179 'high-level':178 'identifi':46,72,466 'if-els':55,155 'implement':248 'increment':259 'input':20,28,303,525,563 'input/output':188 'instanc':222 'instruct':39 'keep':190,272 'level':141,180 'line':374 'local':234 'locat':408 'logic':34,76,128,464 'loop':65 'main':148,173,256 'maintain':185,311 'make':213,282 'mandatori':352 'mani':444 'massiv':154 'meaning':265 'messag':201 'method':2,11,19,38,44,84,109,123,131,134,149,174,215,246,252,274,288,292,346 'methodnam':21 'metric':516 'multipl':54,64,103,240 'must':336 'name':266 'need':221 'nest':51,151 'never':360 'null':225,458 'number':388 'object':16 'occur':552 'oper':137 'opportun':74 'orchestr':161 'origin':325,481,566 'output':369,398,493,543 'paramet':204 'pass':207,363,379,423,498 'pass/fail':376 'pattern':100,285 'practic':212 'preserv':183,196,569 'privat':143 'proceed':426 'process':92 'project':572 'proper':206 're':279,484 're-run':483 'read':175,403,541 'readabl':309 'reduc':4,13,23,150,297 'refactor':1,10,17,254,291,334,345,472,476 'regress':263 'relat':244,342 'repeat':61,94,283,494 'replac':153 'respons':117,271 'restor':479 'result':289,356,534 'retain':323 'return':241 'root':468 'run':338,414,485 'search':370 'separ':83,121,314 'show':357,386 'simplifi':146 'singl':115 'skill':7 'smaller':160 'sourc':47 'source-github' 'specif':87,91,127 'standard':575 'state':223,441,536 'statement':53,165 'static':142,216 'summari':373,385 'surround':349 'switch':59,164 'target':300,522,560 'test':258,320,327,341,355,362,368,393,397,415,422,437,445,486,497,533,545 'threshold':301,523,561 'time':104 'togeth':247 'transform':96 'tupl':238 'type':86,126,198 'type-specif':85,125 'understand':451 'unnecessari':233 'use':138,163,224,237,264,280 'util':133 'valid':75,119,122,192,329 'valu':242 'variabl':235 'verifi':354,410,421,488,502,539 'without':531 'x':380 'y':382 'zero':432","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-04-22T12:52:22.302Z"},{"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-04-22T16:40:17.526Z"}],"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","source":"skills_sh","category":"awesome-copilot","skills_sh_url":"https://skills.sh/github/awesome-copilot/refactor-method-complexity-reduce"},"updatedAt":"2026-04-22T16:40:17.526Z"}}