Skip to content

[code-quality] Reduce cognitive complexity in 46 CRITICAL violations #172

@EthosengineBot

Description

@EthosengineBot

Context

SonarQube analysis identified 46 CRITICAL cognitive complexity violations (S3776) across the codebase, indicating functions that are difficult to understand and maintain.

Hotspot Files

  • shefa/services/insurance-mutual.service.ts - Multiple complex functions
  • elohim/services/content.service.ts - Complex graph traversal logic
  • shefa/services/shefa-compute.service.ts - Complex financial calculations

Issue Pattern

Functions with complexity > 15:

  • Deep nesting (if/else/for/while)
  • Long parameter lists (11+ params)
  • Complex conditional logic
  • Missing function extraction

Acceptance Criteria

  • Extract complex conditions into named functions
  • Break down large functions into smaller units
  • Reduce nesting with early returns
  • Use optional chaining to simplify null checks
  • Reduce cognitive complexity below 15 for all functions
  • Add tests to prevent regression

Estimated Effort

16-24 hours (systematic refactoring)

Priority Justification

CRITICAL - High cognitive complexity directly impacts:

  • Maintainability (harder to modify)
  • Bug risk (harder to reason about)
  • Onboarding (harder for new devs to understand)

Strategic Approach

Week 1: Refactor top 3 hotspot files
Week 2: Systematic review of remaining violations


Created by quality-deep orchestrator - Sprint 3 (SonarQube analysis)

Metadata

Metadata

Assignees

No one assigned

    Labels

    P0Priority 0 - CriticalarchitecturalArchitectural decisions neededbacklogSprint planning backlog - items awaiting prioritization

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions