Limit Cyclomatic Complexity (McCabe Complexity Metric)
Overview
Cyclomatic Complexity Threshold.
ATC Finding Message:
Procedure cyclomatic complexity exceeds threshold
Rationale
Cyclomatic Complexity measures the number of linearly independent paths through a procedure's source code (branch points like IF, ELSEIF, WHEN, WHILE, AND, OR, CATCH). High complexity correlates directly with high defect density, regression risks during refactoring, and poor unit test branch coverage.
Clean ABAP Guideline: Keep cyclomatic complexity under 10 (or maximum 15 for large state dispatches). Extract branches into polymorphically dispatched strategy classes or smaller helper methods.
Non-Compliant
" Anti-pattern: Massive branching complexity score (>20) with nested conditionals
METHOD calculate_discount.
IF iv_region = 'EU'.
IF iv_cust_tier = 'VIP' AND iv_amount > 1000.
rv_disc = 20.
ELSEIF iv_cust_tier = 'GOLD' OR iv_amount > 500.
rv_disc = 15.
...
ENDIF.
ENDMETHOD.Compliant
" Clean ABAP: Delegate calculations to cohesive strategy pattern or rule table
METHOD calculate_discount.
DATA(lo_strategy) = mo_discount_factory->get_strategy( iv_region ).
rv_disc = lo_strategy->calculate( iv_tier = iv_cust_tier iv_amount = iv_amount ).
ENDMETHOD.Configuration & Thresholds
This check can be fine-tuned directly in the ATC Check Variant Editor (CHKV) in Eclipse ADT:
| Parameter Name | Data Type | Default Value | Description & Guidance |
|---|---|---|---|
MAX_COMPLEXITY | Integer | 5 | Maximum allowed cyclomatic complexity score per method (default threshold: 10) |
Suppression
To suppress findings for this rule, append the pseudo-comment to the statement:
" Standard pseudo-comment:
... "#EC MAX_CYCLO_COMP
" SAP CI_ prefix format:
... "#EC CI_MAX_CYCLO_COMPRelated Rules
- Limit Boolean Expression Complexity in Conditional Statements —
#EC MAX_BOOL_EXPR - Limit Control Flow Nesting Depth (Guard Clause Enforcement) —
#EC MAX_NESTING - Limit Method and Constructor Statement Length —
#EC MAX_METHOD_LEN
Technical Details
- Native ATC Class:
ZCL_SKYLINT_MAX_CYCLO_COMP - Implementation File: zcl_skylint_max_cyclo_comp.clas.abap