myerscode/utilities-bags
Immutable “Bag” utilities for fluent manipulation of collection/array data in PHP. Provides a helper class with chainable methods for reading, transforming, and managing data safely without mutation; includes usage and method docs, plus tests and coverage.
Strengths:
Bag::filter()->map()->groupBy()), improving readability.pluck, groupBy, reduce, chunk) overlaps with Laravel’s Collection but offers immutability and non-Laravel alternatives.bag()) integrates seamlessly with existing codebases.Gaps:
Pros:
composer require myerscode/utilities-bags).Collection or native arrays.Cons:
Bag/Collection aliases in codebases.Collection for critical paths.bag() for immutable ops, collect() for mutable ones).array_map, collect())?array_* functions or Laravel’s Collection for immutable operations.Collection (e.g., User::all()->toBag()->filter(...)).spatie/array-to-object or laravel/collection if mutability is needed.->pluck()->groupBy()).array_filter($data) with bag($data)->filter().bag() helper globally (e.g., in service layers).// TODO: Migrate to Bag comments to track progress.BagService facade for centralized usage.Bag inputs/outputs.// Before
$filtered = array_filter($users, fn($u) => $u['active']);
$mapped = array_map(fn($u) => $u['name'], $filtered);
// After
$result = bag($users)->filter(fn($u) => $u['active'])->pluck('name');
array_* patterns in code reviews.Bag to type hints (e.g., function process(Bag $bag): Bag).$users->toBag()), but no native integration.Bag class name collisions (e.g., use UtilitiesBag).Bag as immutable inputs/outputs.Bag consistently.array_* logic as fallback.->filter() vs. array_filter).->sortBy('price')->limit(10)) are more readable than nested array_* calls.Bag state").memory_get_usage()).bag()->take(1000) or hybrid approaches.Bag instances are safe for parallel processing.| Risk | Mitigation | Severity |
|---|---|---|
| PHP 8.5 incompatibility | Upgrade or use polyfills (e.g., php84-polyfill). |
High |
| Method chaining errors | Use ->pipe(fn($bag) => ...) for complex logic. |
Medium |
| Performance bottlenecks | Benchmark vs. Collection; avoid for huge datasets. |
Low |
| Team adoption resistance | Pilot with a small team first. | Medium |
| Breaking changes | Monitor changelog; test on minor updates. | Low |
How can I help you explore Laravel packages today?