digitalrevolution/utils
A PHP 8.3+ utility library of everyday helper classes, focused on array operations such as first/last, find, flatten, map, groupBy, diff, unique, remove, JSON conversion, and path fetching, plus iterable and string helpers.
Strengths:
webmozart/assert) improve validation readability and maintainability, reducing boilerplate in Laravel’s validation layers (e.g., DTOs, request validation, or service logic).flatten, groupBy, fetchByPath) can streamline complex data transformations in Laravel’s collection-like operations (e.g., Eloquent results, API responses, or form submissions).Arrays::toIntList: a focused normalization helper for coercing scalar/array input into a typed int[]. This maps directly onto a recurring Laravel need: sanitizing multi-select form input, comma-separated query params, filter/sort ID lists, and pivot ID arrays before passing them to whereIn() or validation. It is additive and does not alter existing behavior.Closures::unfold) could optimize lazy-loading patterns in Laravel’s service containers or deferred execution (e.g., caching, queued jobs).Gaps:
toIntList is not a validator: it normalizes/coerces but does not replace Validator rules (e.g., integer, exists). It must be paired with validation, not substituted for it, or invalid input may be silently coerced.High:
composer require with no breaking changes (PHP 8.3+).ComparableInterface, Stringable), aligning with Laravel’s modern PHP support.phpmd/phpmd to v3 indicates the static-analysis/quality gate is being kept current (dev-only; no runtime impact).Challenges:
map, filter) overlap with Laravel’s Collection methods, risking confusion. toIntList has no direct Collection equivalent (closest is ->map(fn($v) => (int) $v)->all()), so it is comparatively safe to adopt.flatten) may impact large datasets in Laravel’s Eloquent collections.Validator, FormRequest) may reduce need for custom assertions.null, nested arrays, and duplicate values in toIntList is not documented in the release notes — needs a local test before relying on it in request handling.spatie/laravel-query-builder).first() throw exceptions, which may conflict with Laravel’s null-coalescing patterns (e.g., ->first() in collections).assignByPath mutate arrays in-place, which could cause bugs in immutable Laravel contexts (e.g., DTOs).toIntList converting loose input to integers can mask bad client input if used without upstream validation — a correctness risk in write paths.toIntList worth adopting as the standard for ID-list normalization, replacing scattered array_map('intval', ...) calls?Utils::array()->flatten()) to avoid naming collisions?flatten) a bottleneck for large datasets (e.g., bulk API responses)?Closures::unfold introduce memory leaks in Laravel’s long-running processes (e.g., queues)?toIntList’s documented behaviors for null, empty arrays, floats, numeric strings with whitespace, and duplicates? Does it throw or coerce?app()->make(Assert::class)).Validator rules with fluent assertions (e.g., Assert::notNull($request->input('id'))).FormRequest or DTO validation layers.Arrays::toIntList in FormRequest::prepareForValidation() or a DTO factory to convert multi-select/filter payloads into typed ID arrays before they reach whereIn().Arrays::groupBy($users, fn($u) => $u->role)).Arrays::flatten($array)).Collection::pluck() over Arrays::map() to leverage Laravel’s optimized methods.var_dump() with Stringify::value($object) in middleware or exception handlers.Assert::isArray($result)).Arrays::flatten() vs. collect($array)->flatten()).first() → Arrays::first()).array_map('intval', ...) with Arrays::toIntList() in one or two endpoints, gated by existing validation.throw new \InvalidArgumentException() with Assert::notNull().@method static mixed first(array $array)).map, filter, pluck to prevent collisions with Collections.$this->app->singleton(Utils::class, fn() => new Utils());
phpmd/phpmd v3 bump is a require-dev change only — it does not affect the runtime dependency graph for Laravel consumers.FormRequest and DTOs.// Before
if (empty($request->input('email'))) {
throw new \InvalidArgumentException('Email is required.');
}
// After
Assert::nonEmptyString($request->input('email'), 'Email is required.');
Arrays::groupBy, flatten).Arrays::toIntList behind existing validation; document coercion semantics and add unit tests for null/empty/duplicate input.var_dump with Stringify::value() in middleware or exception handlers.Assert::isInstanceOf($model, User::class)).composer update for all utility fixes.Assert::greaterThan($value, 0, 'Value must be positive')).toIntList is currently documented only by its PR title and signature — verify behavior directly in tests.flatten, fetchByPath) are O(n) over nested depth and can become the hot path in bulk API serialization. toIntList is linear and cheap, but should be applied once at the boundary rather than repeatedly in loops.Closures::unfold remains the only construct worth profiling for retained references.toIntList): malformed client input becomes 0 or is dropped, producing subtly wrong query results rather than explicit errors — pair with validation and assert on expected counts.null can surface as 500s instead of 404/422 responses unless caught and mapped in the exception handler.assignByPath): may corrupt DTOs or cached config arrays shared across requests.webmozart/assert or Laravel Collections; a single pairing session is usually sufficient.toIntList second).null, empty, string, and duplicate input — this is the entire onboarding cost for the new method.How can I help you explore Laravel packages today?