Skip to content

[ARCH] Replace heaviest traits in ClientHandler with injected collaborator objectsΒ #111

Description

@jeromesinolanka

Priority: 🟑 Medium

Description

ClientHandler currently composes 10 traits (see also issue #94 β€” MED-6). While that issue covers the immediate static analysis and maintainability concern, the deeper architectural goal is to move from implicit trait coupling to explicit dependency injection.

The three heaviest traits are the best candidates for extraction into standalone collaborator classes:

Trait Lines Why extract first
PerformsHttpRequests 1096 Already identified as a God Trait in CRIT-2 (#80)
ManagesPromises ~394 Self-contained async logic, minimal state dependencies
ManagesRetries ~247 Clean input/output contract, easy to mock in tests
ManagesConnectionPool ~unknown Infrastructure concern, should be separately testable

With injected collaborators, ClientHandler becomes:

public function __construct(
    private RequestExecutorInterface $executor,
    private RetryManagerInterface $retryManager,
    private PromiseManagerInterface $promiseManager,
    private ConnectionPoolInterface $pool,
    // ...
)

This makes dependencies explicit, enables mocking individual concerns in tests, and eliminates the implicit shared-state problem.

Recommended Approach

This is a significant refactor best done in phases:

  1. Phase 1: Extract ManagesPromises and ManagesRetries (fewer dependencies on handler state)
  2. Phase 2: Extract ManagesConnectionPool
  3. Phase 3: Extract PerformsHttpRequests (coordinate with CRIT-2 resolution)

Preserve the existing public API throughout β€” the extraction should be transparent to callers.

Related

Issue #94 β€” MED-6: God Class via 10 trait compositions
Issue #80 β€” CRIT-2: PerformsHttpRequests God Trait

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

architectureStructural or design-level changedependenciesPull requests that update a dependency fileneeds-triageNeeds review before work beginspriority: mediumCode quality, completeness, or maintainabilityrefactorRestructures code without changing behaviourstaleNo activity for 60+ daystech-debtAccumulated shortcuts that need to be paid down

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions