Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separation of Collection Class into Trait and Interface #1262

Merged
merged 2 commits into from
Dec 24, 2024

Conversation

valzargaming
Copy link
Member

Description

This PR introduces a modular architecture for the Collection functionality by splitting it into:

  1. CollectionTrait: Implements the reusable logic of the Collection class.
  2. CollectionInterface: Specifies the contract for collection-related operations.
  3. Updated Collection Class: Now leverages CollectionTrait and implements CollectionInterface.

Changes Introduced

  1. Addition of CollectionTrait.php:
  • Moved shared methods from Collection to a trait for reuse.
  • Includes utility functions such as toArray, filter, map, and others.
  1. Addition of CollectionInterface.php:
  • Declares method signatures for offsetGet, offsetSet, offsetExists, offsetUnset, toArray, and other collection operations.
  1. Refactoring of Collection.php:
  • Collection now uses the CollectionTrait.
  • Implements CollectionInterface.
  • Maintains backward compatibility while adhering to the interface contract.

Why This Change?

  • Separation of Concerns: Isolates the behavior (trait) and contract (interface), ensuring modularity.
  • Improved Testability: With a clearly defined interface, mocking and testing become more straightforward.
  • Reusability: The trait can be applied to other classes requiring similar functionality.
  • Consistency: Aligns the architecture with best practices for maintainable and extensible codebases.

Impact on Existing Code

  • Backward Compatibility: The refactored Collection class maintains the same public API as before.
  • Dependencies: Any external code dependent on Collection should continue to work without modification.

@valzargaming valzargaming requested review from Log1x and Exanlv November 19, 2024 21:16
@valzargaming valzargaming merged commit ad0b2d7 into master Dec 24, 2024
2 checks passed
valzargaming added a commit that referenced this pull request Dec 24, 2024
This patches a mistake that was missed with #1262
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