refactor-method-complexity-reduce

Refactor AdvPL/TLPP methods by extracting helper functions to reduce cognitive complexity.

115|54|Updated May 25, 2026
One-click install
npx skills add https://github.com/totvs/engpro-advpl-tlpp-skills --skill refactor-method-complexity-reduce-totvs
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor-method-complexity-reduce
Source: https://github.com/totvs/engpro-advpl-tlpp-skills/tree/main/skills/advpl-tlpp/refactor-method-complexity-reduce
Command: npx skills add https://github.com/totvs/engpro-advpl-tlpp-skills --skill refactor-method-complexity-reduce-totvs

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

High cognitive complexity makes AdvPL/TLPP methods hard to read, maintain, and safely change, increasing defect risk and slowing development.

Core Features & Use Cases

  • Complexity audit: Identifies common complexity sources like nested conditionals, long if/else chains, repeated blocks, and multiple conditional loops.
  • Helper extraction refactor: Extracts validation, type/case-specific handling, repeated transformations, and utility logic into focused Validate* and handler helpers.
  • Behavior preservation with guardrails: Ensures the refactor retains original inputs/outputs and error handling, with explicit testing and cognitive-complexity verification.

Quick Start

Use the skill to refactor the method you specify for ${input:methodName} so it meets the target ${input:complexityThreshold} by extracting well-named helper methods while preserving functionality and validating with tests that report failed=0.

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 in AdvPL methods with deeply nested conditionals?

Reduce cognitive complexity in AdvPL methods by extracting focused helper methods like validation and case-specific handlers from deeply nested conditionals. This refactor preserves original behavior while making the User Function easier to maintain.

What is the best way to refactor long switch chains in TLPP code?

The best way to refactor long switch chains in TLPP code is extracting type and case-specific handling into focused helper methods. This reduces cognitive complexity below your specified threshold while preserving original inputs and error handling.

How can I verify behavior preservation when extracting helper methods from AdvPL code?

Verify behavior preservation when extracting helper methods by running tests and explicitly checking that failed=0. You must also confirm successful compilation and validate the final cognitive complexity metric to ensure the refactor is safe.

Can I refactor complex boolean expressions in AdvPL without changing error handling?

Yes, you can refactor complex boolean expressions in AdvPL without changing error handling. The extraction process targets focused utility logic while strictly retaining original inputs, outputs, and existing error handling guardrails.

When do I need to extract helper methods for code quality in TLPP?

You need to extract helper methods for code quality in TLPP when a single User Function contains repeated blocks, complex boolean expressions, or long if/else chains. This reduces defect risk and slows development caused by high cognitive complexity.

Does complexity reduction refactoring work with AdvPL code containing repeated transformation blocks?

Yes, complexity reduction refactoring works with AdvPL code containing repeated transformation blocks by extracting these repeated blocks into focused utility helpers. This safely lowers the cognitive complexity metric while maintaining the original functionality.