Software Development
Code Complexity Auditor
Scores functions on cyclomatic complexity, cognitive load, and length, then flags thresholds exceeded and suggests refactoring into smaller testable units. Useful for preventing maintenance debt from rapidly generated code. Tech leads reviewing AI-assisted PRs, engineers maintaining code they did not originally write, platform teams enforcing a complexity budget across a portfolio of services. The most insidious failure mode is not broken code but unmaintainable code — 120-line functions with nested conditionals and eight parameters that work today but become expensive to debug in three months. Static complexity metrics catch these cases reliably, but most teams do not run them consistently. A pre-review auditor flags the functions most likely to accumulate technical debt and proposes specific decompositions.
One-Time Purchase
$19.99
Complexity Audit — src/services/checkout.ts
Functions scanned: 14 · Thresholds: cyclomatic 10, cognitive 15, params 5, length 60
Verdict
Refactor required before next merge. Three functions exceed cyclomatic 10, two exceed cognitive 15, and processCheckout is a 148-line god-function carrying inventory, coupons, tax, payment, and order persistence. One justifiable exception (resolvePaymentRouting) is documented below.
Hotspots (worst first)
Findings
| Function | Cyclomatic | Cognitive | Params | Length | Severity |
|---|---|---|---|---|---|
processCheckout | 23 | 34 | 3 | 148 | Critical |
applyDiscountRules | 17 | 21 | 6 | 54 | High |
buildOrderSummary | 8 | 9 | 4 | 74 | Medium |
resolvePaymentRouting | 19 | 14 | 2 | 58 | Exception |
reservePaymentMethod | 7 | 8 | 3 | 41 | OK |
emitOrderEvents | 6 | 6 | 2 | 38 | OK |
processCheckout Critical
A single function body handles inventory validation, coupon stacking, tax, payment dispatch, and order record creation. The nested coupon-stacking conditionals alone contribute 11 cyclomatic points. Test coverage on this function is currently 41%, and three of the last five production incidents on checkout traced back here.
Refactor. Decompose into five focused functions. Each extracted function preserves the return type and side-effect contract of the corresponding block, so the public signature is unchanged.
Before
One 148-line function
Inventory + coupons + tax + payment + persistence inline
After
One orchestrator + five helpers
Each helper is independently testable
// AFTER
async function processCheckout(cart: Cart, user: User, options: CheckoutOptions): Promise<OrderResult> {
await validateInventory(cart);
const discountedCart = await applyCoupons(cart, options.couponCodes);
const taxedCart = await applyTax(discountedCart, user.address);
const paymentResult = await dispatchPayment(taxedCart, user.paymentMethod);
return createOrderRecord(taxedCart, user, paymentResult);
}
async function validateInventory(cart: Cart): Promise<void> {
for (const item of cart.items) {
const stock = await inventoryService.getStock(item.sku);
if (stock < item.quantity) {
throw new InsufficientStockError(item.sku, stock, item.quantity);
}
}
}
async function applyCoupons(cart: Cart, codes: string[]): Promise<Cart> {
let discounted = { ...cart };
for (const code of codes) {
const coupon = await couponService.resolve(code);
discounted = coupon.apply(discounted);
}
return discounted;
}
applyDiscountRules High
Six positional parameters (loyaltyTier, promoCode, isEmployee, cartTotal, itemCount, regionCode) and three levels of nested coupon-stacking logic. The parameter list alone is a maintenance trap — call sites have already swapped arguments twice in the past 90 days according to git blame.
Refactor. Introduce a DiscountContext value object and a tier-rate map. Keep the original signature as a thin shim so call sites do not change.
interface DiscountContext {
loyaltyTier: string;
promoCode: string | null;
isEmployee: boolean;
cartTotal: number;
itemCount: number;
regionCode: string;
}
function applyDiscountRulesFromContext(ctx: DiscountContext): number {
const base = resolveBaseDiscount(ctx);
const promo = resolvePromoDiscount(ctx.promoCode, ctx.cartTotal);
return Math.min(base + promo, ctx.cartTotal);
}
function resolveBaseDiscount(ctx: DiscountContext): number {
if (ctx.isEmployee) return ctx.cartTotal * 0.20;
const rates: Record<string, number> = { gold: 0.15, silver: 0.10, bronze: 0.05 };
return ctx.cartTotal * (rates[ctx.loyaltyTier] ?? 0);
}
Estimated after refactor: cyclomatic 2, cognitive 2.
buildOrderSummary Medium
Exceeds length threshold (74 lines) but branching is flat and linear. Low incident risk, but extraction improves readability and unit-test isolation for the currency and address formatters.
Refactor. Extract formatCustomerName, formatAddress, formatLineItem, formatTotals. No behavioral change.
resolvePaymentRouting Justifiable Exception
Cyclomatic 19 encodes a 16-rule gateway-selection state machine driven by regional financial compliance. Each branch maps to a documented regulatory citation. Cognitive complexity stays at 14 (below threshold) because the branching is structurally flat — a single switch on regionCode + paymentMethodKind. Decomposing would scatter the rule set across files and raise the risk of inconsistent updates when a rule changes.
Action. No refactor. Add a rule-table comment block above the function mapping each branch to its compliance reference.
Recommended Refactor Order
Sequence (highest leverage first)
Before / After Summary
| Function | Before | After Refactor |
|---|---|---|
processCheckout | 23 / 34 / 148 | 1 / 3 / 18 |
applyDiscountRules | 17 / 21 / 6 params | 2 / 2 / 1 param |
buildOrderSummary | 8 / 9 / 74 | 3 / 3 / 22 |
resolvePaymentRouting | 19 / 14 / 58 | Exception (no change) |
| File-level worst case | cyclomatic 23 | cyclomatic 3 (excl. exception) |
This audit reviews a hypothetical file for illustration. Run the proposed changes behind a feature-flagged checkout shadow before retiring the original code path.
This sample illustrates the skill's output format. Names, metrics, and operational details are illustrative unless the artifact explicitly analyzes public information.
View full sample →
All sales final. No refunds on digital products.
Includes support for Claude Code, Codex, OpenClaw, and Google Antigravity in the same license.
Also in Specs & Governance
Bundle price: $55. Compare this skill with the full workflow bundle or Pro access.
Best for
Engineering leads conducting structured code-quality reviews on a service before a refactor decision, tech leads producing a complexity-debt view to justify a refactor sprint to product, and engineering managers monitoring complexity trends across a codebase as part of the quarterly health view. Most valuable on services with 10K-200K lines where complexity has accumulated unevenly and the team needs a defensible list of the worst offenders before deciding what to refactor.
Not ideal for
Greenfield or very small codebases where complexity is not yet meaningful. Also a poor fit as a substitute for actually deciding which complexity is worth fixing; the auditor surfaces complexity hotspots, but the call on which ones are real debt vs essential complexity still requires engineering judgment.
Included in this purchase
- Claude Code, Codex, OpenClaw, and Google Antigravity skill files.
- Setup guidance for the right adapter in your workspace.
- One-time license for the purchased skill version.
Setup
Plan for a short setup in the repository or workspace where the skill will run. Some coding familiarity helps for implementation-heavy outputs.
Related Skills
$19.99
One-time license
$19.99
One-time license
$19.99
One-time license
Future Updates
This purchase includes the current version of the skill. If you want future adapter updates — meaning compatibility and packaging updates as supported platforms evolve — plus new catalog additions included automatically, upgrade to Pro.