Skip to content

Refactor DI passes to reduce code duplication and improve consistency#28

Closed
f3l1x wants to merge 1 commit intomasterfrom
claude/code-simplifier-plugin-ZhAoj
Closed

Refactor DI passes to reduce code duplication and improve consistency#28
f3l1x wants to merge 1 commit intomasterfrom
claude/code-simplifier-plugin-ZhAoj

Conversation

@f3l1x
Copy link
Copy Markdown
Member

@f3l1x f3l1x commented Mar 26, 2026

Summary

This PR refactors the DI (Dependency Injection) passes to eliminate code duplication, improve maintainability, and enhance consistency across the codebase. The changes focus on extracting repeated logic into reusable methods and simplifying conditional structures.

Key Changes

  • EventPass.php:

    • Simplified event dispatcher registration logic by combining conditional branches into a single ternary expression
    • Refactored worker limits configuration by extracting repeated listener registration patterns into a loop-based approach, reducing ~45 lines of code to ~20 lines
  • BuilderMan.php:

    • Extracted common failure transport validation logic into a new private method getValidatedFailureTransports()
    • Simplified getTransportToFailureTransportsServiceMapping() and getFailedTransports() methods to reuse the extracted validation logic, eliminating duplicate code and reducing maintenance burden
  • ConsolePass.php:

    • Replaced all instances of $this->extension->getContainerBuilder() with $this->getContainerBuilder() for consistency
    • Replaced all instances of $this->extension->prefix() with $this->prefix() for consistency
    • These changes improve code readability and leverage inherited methods from the parent class
  • TransportPass.php:

    • Fixed inefficiency where $transportDefinition was retrieved separately when $transportDef was already available
    • Removed unnecessary variable assignment and used the already-defined $transportDef directly

Notable Implementation Details

  • The new getValidatedFailureTransports() method returns a structured array containing both the failure transport name and service name, allowing both calling methods to extract their needed data without duplicating validation logic
  • Worker limits configuration now uses a declarative array structure that makes it easy to add or modify limits in the future
  • All changes maintain backward compatibility and existing functionality

https://claude.ai/code/session_01RpDZTC6P3Lh78s4YbDZR2j

- BuilderMan: Extract getValidatedFailureTransports() to eliminate duplicated validation in getTransportToFailureTransportsServiceMapping() and getFailedTransports()
- EventPass: Consolidate 5 worker limit if-blocks into data-driven loop; simplify dispatcher registration with ternary
- TransportPass: Reuse $transportDef instead of re-fetching same definition
- ConsolePass: Use inherited $this->prefix() and $this->getContainerBuilder() consistently

https://claude.ai/code/session_01RpDZTC6P3Lh78s4YbDZR2j
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.86%. Comparing base (ab8d1cc) to head (3eda4ae).

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #28      +/-   ##
==========================================
+ Coverage   95.83%   95.86%   +0.03%     
==========================================
  Files          25       25              
  Lines         648      629      -19     
==========================================
- Hits          621      603      -18     
+ Misses         27       26       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@f3l1x f3l1x closed this Mar 26, 2026
@f3l1x f3l1x deleted the claude/code-simplifier-plugin-ZhAoj branch March 26, 2026 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants